The method isn't running even though there isn't any errors in logcat i know there are questions like this one although none of them helped me
public class AddPlayerFragment extends Fragment implements View.OnClickListener,AdapterView.OnItemSelectedListener {
EditText playerName, playerAge, playerMvps, playerChampions, playerPoints;
Button addPlayer;
Spinner playerTeam;
DatabaseReference mDatabase;
ArrayList<String> teamNames,teamId;
String selectedId;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_add_player, container, false);
mDatabase = FirebaseDatabase.getInstance("https://aminandroid-45afc-default-rtdb.europe-west1.firebasedatabase.app/").getReference();
playerName = (EditText) v.findViewById(R.id.addplayer_name);
playerAge = (EditText) v.findViewById(R.id.addplayer_age);
playerChampions = (EditText) v.findViewById(R.id.addplayer_champions);
playerPoints = (EditText) v.findViewById(R.id.addplayer_points);
playerMvps = (EditText) v.findViewById(R.id.addplayer_mvps);
playerTeam = (Spinner) v.findViewById(R.id.addplayer_team);
addPlayer = (Button) v.findViewById(R.id.addplayer_button);
addPlayer.setOnClickListener(this);
fillTeamsNameAndId();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_dropdown_item, teamNames);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
playerTeam.setAdapter(adapter);
playerTeam.setOnItemSelectedListener(this);
return v;
}
This method here fills the Array list "teamName" that is used in the ArrayAdapter in the spinner and the arraylist "teamId" that i use somewhere else in the code
private void fillTeamsNameAndId(){
teamNames = new ArrayList<String>();
teamId = new ArrayList<String>();
mDatabase.child("Teams").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot ds : snapshot.getChildren()) {
String name = String.valueOf(ds.child("name").getValue());
String id = String.valueOf(ds.child("tid").getValue());
teamNames.add(name);
teamId.add(id);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
This is the OnItemSelected Method that isn't being called i put all of the code above in case the error is there and not in the method code since i triple checked the documentation and it matches the code here
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("item", "dddddd");
((TextView) adapterView.getChildAt(i)).setTextColor(Color.BLACK);
selectedId = teamId.get(i);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
}