confucius
confucius

Reputation: 13327

change background of textview for listview item get focused

i have this listview enter image description here

each listview item has a textview that have background , i want to change the background of the textview of listview item get focused .

Upvotes: 0

Views: 640

Answers (2)

Nikolay Ivanov
Nikolay Ivanov

Reputation: 8935

You should use Selector.
Edit: Use selector drawable as a background for ListView elements, or specify a android:listSelector for a ListView

Upvotes: 1

ilango j
ilango j

Reputation: 6037

you have change background color in onfocusChangeListener. Try with following code,

livView.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                TextView tv=(TextView)v.findViewById(R.id.yourId);
                if(hasFocus){
                    tv.setBackgroundColor(bg_color);
                }
            }
        });

Upvotes: 0

Related Questions