我想高亮显示简单列表视图的默认选择。突出显示这里经常讨论的onItemClickListener,但是如何突出显示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);
答案 0 :(得分:0)
您可以使用this
制作自定义列表视图按如下方式更改getView()函数:
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;
}
在program_list.xml
中更改textview如下:
<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" />