How to set ListView selected item alternet text color in android

前端 未结 5 1264
猫巷女王i
猫巷女王i 2021-01-07 01:31

I have a custom listview with a imageview and an textview. I want when user select a item the textview color should change and all the other textview should remain default.<

5条回答
  •  醉梦人生
    2021-01-07 01:46

    Implement setOnItemClickListener for the listView

    listView.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView adapterView, View view, int position,
                    long arg3) {
                RelativeLayout relativeLayout = (RelativeLayout) view.getParent();
                TextView textView = (TextView) relativeLayout.getChildAt(0);
                ImageView imaegView = (ImageView) relativeLayout.getChildAt(1);
    
                textView.setTextColor(Color.RED);
               // Perform whatever action for your textView and imageView
    
    
            }
    
        });
    

提交回复
热议问题