我在每一行都创建了带有复选框和文本视图(带有自定义背景)的 ListView。当我单击一行时,复选框和 textview 会用 listview 行突出显示,但我想在单击行后仅突出显示没有复选框和 textview 的 listview 行。请问你能帮帮我吗?
这就是我点击一行后想要的:http: //tinypic.com/r/14kfpza/5。
这是我点击一行后得到的:http: //tinypic.com/r/2mr5w9c/5。
谢谢
我的列表视图适配器:
public class MyAdapter<String> extends ArrayAdapter<String>{
Context ctx;
List<String> content;
public MyAdapter(Context context, List<String> objects) {
super(context, R.layout.listview_row ,objects);
this.ctx = context;
this.content = objects;
}
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
if(row == null){
LayoutInflater inflater=getLayoutInflater();
row=inflater.inflate(R.layout.listview_row, parent, false);
}
TextView desc = (TextView)row.findViewById(R.id.textView1);
String name = content.get(position);
desc.setText(name.toString());
return row;
}
}
listview_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="Large Text"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:background="@drawable/textview_bg"
android:textAppearance="?android:attr/textAppearanceLarge" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/textView1"
android:layout_marginRight="5dp"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</RelativeLayout>