0

I want to highglight the default selection of a simple list view. Highlighting works, as frequently discussed here, with the onItemClickListener, but how can I highlight the default selection of the simple_list_view?

xml:

<ListView
android:choiceMode="singleChoice"
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>

java:

listView = (ListView) popupView.findViewById(R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
               int position, long id) {
                 //this is of course not called for the default selection
                }
});
listView.setItemChecked(0, true);
listView.setSelection(0);
  • I guess you can find your answer in this topic: http://stackoverflow.com/questions/5925892/android-how-do-i-highlight-a-row-in-listview – Savail Aug 11 '14 at 17:45

1 Answers1

0

You can make custom listview using this

Change getView() function as follows:

public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    Holder holder=new Holder();
    View rowView;        
         rowView = inflater.inflate(R.layout.program_list, null);
         holder.tv=(TextView) rowView.findViewById(R.id.textView1);
         holder.img=(ImageView) rowView.findViewById(R.id.imageView1);       
     holder.tv.setText(result[position]);

     //this thing changes color
     if (position == 0)
     {
         //R.color.gold is required color in first item.
         holder.tv.setBackgroundColor(R.color.gold);
     }
     holder.img.setImageResource(imageId[position]);         

    return rowView;
}

In program_list.xml

Change textview as follows:

<TextView
    android:id="@+id/textView1"
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textSize="25dp"
    android:text="TextView" />
NikhilS
  • 83
  • 2
  • 11