我试图为列表视图实现setonitemclicklistner。当我单击任何项目时,它始终显示相同的值。 这是我的代码。
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, donorList);
listView.setAdapter(arrayAdapter);
final DatabaseReference myRef = database.getReference("donors");
myRef.child(city).child(group).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
final Donor donor = dataSnapshot.getValue(Donor.class);
donorInfo.add(donor);
final String donorInfo = donor.name + " \n" + donor.contuctNumber;
donorList.add(donorInfo);
arrayAdapter.notifyDataSetChanged();
listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String name = donor.name;
final Dialog dialog = new Dialog(DonorList.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.details);
dialog.setTitle("Custom Dialog");
//adding text dynamically
TextView t3 = ( TextView ) dialog.findViewById(R.id.textView5);
t3.setText(name);