suggestionsRowLayout 也不适合我。
就我而言,我只需要更改每行的背景颜色和文本颜色。
所以我只是在我的 SuggestionsAdapter 中修改了从 newView() 返回的 View 的布局:
public class SuggestionsAdapter extends CursorAdapter
{
public SuggestionsAdapter(Context context, Cursor cursor)
{
super(context, cursor, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor)
{
TextView tv = (TextView) view.findViewById(R.id.item);
tv.setText(cursor.getString(COL_NAME));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// I modified the layout of search_item.xml
View view = inflater.inflate(R.layout.search_item, parent, false);
return view;
}
}
search_item.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp" >
<TextView
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/red" />
</LinearLayout>
您当然可以将背景设置为可绘制的选择器以用于点击突出显示。