Note that there are some explanatory texts on larger screens.

plurals
  1. POUnselect the ListView Item onClick in android
    text
    copied!<p>What is happening i have a listview on which i putting background color change on selection.As well as by default i am putting the first listview item selected as </p> <pre><code>public class OneWayFlightResult extends BaseAdapter { private Activity activity; private ArrayList&lt;HashMap&lt;String, String&gt;&gt; data; private static LayoutInflater inflater=null; public OneWayFlightResult(Activity a, ArrayList&lt;HashMap&lt;String, String&gt;&gt; d) { activity = a; data=d; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { // TODO Auto-generated method stub return data.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; if(convertView==null) vi = inflater.inflate(R.layout.row, null); TextView flightTime = (TextView)vi.findViewById(R.id.flightTime); // title TextView flightCompanyName = (TextView)vi.findViewById(R.id.flightCompanyName); // title TextView flightNumber = (TextView)vi.findViewById(R.id.flightNumber); // title ImageView flightLogo = (ImageView)vi.findViewById(R.id.flightLogo); HashMap&lt;String, String&gt; flight = new HashMap&lt;String, String&gt;(); flight = data.get(position); flightTime.setText(flight.get(TestActivity.FlightTime)); flightCompanyName.setText(TestActivity.FlightCompanyName); flightNumber.setText(TestActivity.FlightNumber); if(position == 0){ vi.setBackgroundResource(R.drawable.selection_effect); vi.setSelected(true); } return vi; } </code></pre> <p>This is XML file i am using in this <strong>selection_effect.xml</strong></p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_focused="true"&gt; &lt;shape&gt; &lt;solid android:color="#ffffff" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item&gt; &lt;shape&gt; &lt;solid android:color="#00a7eb" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;/selector&gt; </code></pre> <p>So by default this the first list view is selected.Now when the user select the another listview item the first one remains selected and the other one also got the same effect.So how could change the effect on click of the listview item dynamically .Means by default first item comes up selected when the user selects other item other one get selected the effect from the default one get removed </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload