没有在setOnItemClicklistner中获得位置

时间:2018-11-03 16:17:03

标签: android listview arraylist onitemclicklistener

我试图为列表视图实现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);

0 个答案:

没有答案