Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't make my ListView selectable, on press the element doesn't highlight

Hi I created a ListView extending the ListActivity class, it works all fine but when I click on a item it doesn't get highlighted.

This is how I populate the list:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.row_event, null);
    }
    Event ev = items.get(position);

    if (ev != null) {
        //line one
        TextView eventName = (TextView) v.findViewById(R.id.toptext);
        //line two
        TextView eventDate = (TextView) v.findViewById(R.id.bottomtext);

        if (eventName != null) {
            eventName.setText(ev.getEventName());                            }
        if (eventDate != null){
            eventDate.setText(ev.getEventDate());
        }
    }
return v;
}
}

Thank you!

like image 780
MataMix Avatar asked Dec 28 '22 17:12

MataMix


1 Answers

Make sure that the two textviews are set to android:focusable="false" so they do not override the listview's focus behavior. Also, the problem may be from setting a background for the textviews. Setting the background for the ListView items overrides the default focus behavior.

like image 101
A. Abiri Avatar answered Jan 11 '23 06:01

A. Abiri