Jeeten Parmar
Jeeten Parmar

Reputation: 5757

Change color of ListView Selected Item and also change different color to non selected Items

Listview Items have default color Black. Now, when user clicks on any Item, I want to change its color as Gray so remaining Items color will be Black. If user again clicks on another item then that Item's color should become Gray and remaining items of black color.

I know for one time changing color but after clicking on another item, I don't know how to change all remaining Items color.

Upvotes: 0

Views: 696

Answers (2)

Ketan Ahir
Ketan Ahir

Reputation: 6728

try following code in your onItemClickListener

listview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                for (int i = 0; i < adapter.getCount(); i++) {
                    View item = listview.getChildAt(i);
                    if (item != null) {
                        item.setBackgroundColor(Color.BLACK);
                    }
                }
                arg1.setBackgroundColor(Color.GRAY);
            }
        });

Upvotes: 1

Saj
Saj

Reputation: 839

In your customAdater class

  convertView.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {

         TextViewName.setTextColor(getApplication().getResources()
                    .getColor(R.color.YOUR_COLOR));

    }

   });

Upvotes: 0

Related Questions