无法使我的ListView可选,按下元素不突出显示

时间:2022-11-03 08:34:56

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.

嗨我创建了一个扩展ListActivity类的ListView,它工作得很好但是当我点击一个项目时它没有突出显示。

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!

谢谢!

2 个解决方案

#1


10  

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.

确保将两个textviews设置为android:focusable =“false”,这样它们就不会覆盖listview的焦点行为。此外,问题可能来自为textviews设置背景。设置ListView项的背景将覆盖默认焦点行为。

#2


0  

take a look at this site:

看看这个网站:

http://udinic.wordpress.com/2011/07/01/selectablelistview-make-selection-work/

http://udinic.wordpress.com/2011/07/01/selectablelistview-make-selection-work/

#1


10  

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.

确保将两个textviews设置为android:focusable =“false”,这样它们就不会覆盖listview的焦点行为。此外,问题可能来自为textviews设置背景。设置ListView项的背景将覆盖默认焦点行为。

#2


0  

take a look at this site:

看看这个网站:

http://udinic.wordpress.com/2011/07/01/selectablelistview-make-selection-work/

http://udinic.wordpress.com/2011/07/01/selectablelistview-make-selection-work/