如何在ListView中使用onView的ImageView?

时间:2018-02-22 18:04:15

标签: android android-layout android-studio android-imageview

我有一个listview,在我的listview中我使用了imageview,对于Listview和imageview,我使用了onClick方法,现在我的问题是,当我第一次点击imageview时,第一次listview ClickListener它工作,然后下一次点击imageview ClickListener它工作......

我的代码:

String[] classColumns = {"class_name" , "class_day" , "class_time" , "university_name" , "class_id"};

int[] listView_Items = {R.id.item_ClassName , R.id.item_ClassDay , R.id.item_ClassTime , R.id.item_UniName};

    final SimpleAdapter adapter = new SimpleAdapter(getContext() , hashMap , R.layout.listview_items ,
            classColumns , listView_Items);

    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

            HashMap<String, Object> obj = (HashMap<String, Object>) adapter.getItem(position);
            String name = (String) obj.get("class_name");
            String day = (String) obj.get("class_day");
            String class_id = (String) obj.get("class_id");
            Toast.makeText(getContext() , "class id : " + class_id , Toast.LENGTH_SHORT).show();

            ImageView addStudent_imgView = (ImageView) view.findViewById(R.id.imageView2);
            addStudent_imgView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());

                    View viewAlert = getActivity().getLayoutInflater().inflate(R.layout.listview_addstudent_items , null);

                    dialog.setView(viewAlert);
                    dialog.show();

                }
            });
}
    });

0 个答案:

没有答案