1

单击列表时,我想更改图像。单击列表中的位置将更改图像。另一个列表位置的 ImageView 图像将是相同的,但我没有成功。

当我选择一个列表项图像时,视图显示右图标图像,当我取消选择此位置时,ImageView 显示箭头图像。

   public View getView(final int position, View convertView,
        final ViewGroup parent) {
    // TODO Auto-generated method stub

    View row = convertView;
    if (row == null) {

        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        row = inflater.inflate(mLayoutResourceId, parent, false);

        mHolder = new BusinessHolder();

        mHolder.mTxt_STDNAME = (TextView) row
                .findViewById(R.id.txt_stdName);

        mHolder.mTxt_STDCOURSE = (TextView) row
                .findViewById(R.id.txt_stdCourse);

        mHolder.mTxt_STDYEAR = (TextView) row
                .findViewById(R.id.txt_stdYear);        

        mHolder.mImageViewSelection = (ImageView) row
                .findViewById(R.id.img_selection);

        mHolder.mLin_layout=(LinearLayout)       row.findViewById(R.id.Layout_listText);


        row.setTag(mHolder);

    } else {

        mHolder = (BusinessHolder) row.getTag();
    }

        mHolder.mTxt_STDNAME.setText(FacultyDatabaseHalper.mStudentStudentName.get(position));

        mHolder.mTxt_STDCOURSE.setText(FacultyDatabaseHalper.mStudentCourse.get(position));

        mHolder.mTxt_STDYEAR.setText(FacultyDatabaseHalper.mStudentYear.get(position));


        mHolder.mLin_layout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                if(myposition.contains(String.valueOf(position))){


                     myposition.remove(String.valueOf(position));


                     mHolder.mImageViewSelection.setImageResource(R.drawable.arrow);


                    }else{


                     myposition.add(String.valueOf(position));




                       mHolder.mImageViewSelection.setImageResource(R.drawable.check);

                    }

                    notifyDataSetChanged();

            }
        });

    return row;
    }

    public class BusinessHolder {

    TextView mTxt_STDNAME, mTxt_STDYEAR,
            mTxt_STDCOURSE; 
    ImageView mImageViewSelection;

    LinearLayout mLin_layout;

    }

    }
4

1 回答 1

0

你需要让听众在listView而不是在视图上,这也会给你位置

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

       Object o = prestListView.getItemAtPosition(position);
       prestationEco str=(prestationEco)o;//As you are using Default String Adapter
       Toast.makeText(getBaseContext(),str.getTitle(),Toast.LENGTH_SHORT).show();
        }
    });
于 2013-03-09T09:05:14.693 回答