开发者

double items get selected when one item is clicked in listview

I have a custom listview with an image and textview. When I select the first item the last item also gets selected and image changes for both items. I couldn't find what is the problem. pls help..

Here is the code for it.

EDIT

lv5=(ListView)findViewById(R.id.ListView05);
lv5.setAdapter(new ArrayAdapter<String>(this,R.layout.productselecttext,R.id.pstext,arr));     
lv5.setOnItemClickListener(new OnItemClickListener(){ 
public void onItemClick(AdapterView<?> parent, View view, int positi开发者_如何学编程on, long id) {   
if(lv5.getItemAtPosition(position) != null)
    { ImageView icon = (ImageView)view.findViewById(R.id.oi); icon.setImageResource(R.drawable.v); } } }); 


Use like this in your listview.setOnClickListener method:

@Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
            if(view.findViewById(R.id.R.id.oi).getVisibility()==ImageView.VISIBLE){
                              ImageView icon = (ImageView)view.findViewById(R.id.oi); 
                              icon.setImageResource(R.drawable.v); 
                            } } });


I've found a solution!!

With full expelantion and code example, here: http://www.codegod.biz/WebAppCodeGod/Android-ListView-with-dynamic-Images-AID588.aspx

It was a long search for a solution..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜