CopyPastor

Detecting plagiarism made easy.

Score: 1.8256457448005676; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2016-03-03
by AmeeJoshi

Original Post

Original - Posted on 2014-01-21
by T.V.



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can change color of the selected list view item. Below code may helpful.
first put this in your listview
android:listSelector="@drawable/list_selector"
Then create xml files in drawable to control the diferent states
@drawable/list_selector
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/> <item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/> </selector>
@drawable/list_item_bg_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="@color/list_background" android:endColor="@color/list_background" android:angle="90" /> </shape>
@drawable/list_item_bg_pressed
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="@color/list_background_pressed" android:endColor="@color/list_background_pressed" android:angle="90" /> </shape>
In your ListView Selection
listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position,long arg3) { view.setSelected(true); ... } }
Don't forget to add list_background_pressed and list_background to your values/color.xml or just set the color manually in each file.
And I Believe that when you use setSelection(int pos) that will automatically uset the layout you've set as selectected.



I've managed to accomplish that by making several selectors for the different states
first put this in your listview
android:listSelector="@drawable/list_selector"
Then create xml files in drawable to control the diferent states **@drawable/list_selector**
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/> <item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/> </selector>
**@drawable/list_item_bg_normal**
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="@color/list_background" android:endColor="@color/list_background" android:angle="90" /> </shape>
**@drawable/list_item_bg_pressed**
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="@color/list_background_pressed" android:endColor="@color/list_background_pressed" android:angle="90" /> </shape>
In your ListView Selection listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position,long arg3) { view.setSelected(true); ... } }
Don't forget to add **list_background_pressed** and **list_background** to your values/color.xml or just set the color manually in each file. And I Believe that when you use **setSelection(int pos)** that will automatically uset the layout you've set as selectected.
Hope it helps.

        
Present in both answers; Present only in the new answer; Present only in the old answer;