【发布时间】:2014-05-01 07:46:26
【问题描述】:
我有一个ListView,它是使用SimpleAdapter 生成的。我在与SimpleAdapter 一起使用的xml 文件中有一个textview 和一个ImageView。图像视图首先设置为不可见。单击 Listview 中的一行时,Imageview 变为可见。我想做的是:
如果我在 Listview 中有 4 行并且如果我单击第 1 行,那么 ImageView 应该在第 1 行可见,然后如果我单击第 2 行,则 imageview 应该从第 1 行变得不可见,并且应该只在第 2 行可见。
我已经完成了以下操作,但它的工作方式如下:
如果我单击第 1 行,则 ImageView 在第 1 行可见。然后,如果我单击第 2 行,则 ImageView 在第 2 行上可见,并且在第 1 行上也可见。我想让它从第 1 行不可见,并且只显示在点击的行上。
谁能一步一步指导我如何做到这一点。我的代码和xml如下:
myactivity.class
final ListAdapter k=new SimpleAdapter(getActivity(),val,R.layout.senttaskdata2,new String[]{"rname"},new int[]{R.id.textView1})
{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final View v = super.getView(position, convertView, parent);
ImageView im=(ImageView)v.findViewById(R.id.ImageView3);
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
ImageView im=(ImageView)arg1.findViewById(R.id.ImageView3);
setVisibility(arg1.VISIBLE);
});
return v;
}
};
sent.setAdapter(k);
senttaskdata2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@android:color/transparent" >
<ImageView
android:id="@+id/imageView3"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:src="@drawable/test2" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="TextView"
android:textColor="@android:color/darker_gray"
android:textSize="11sp" />
</RelativeLayout>
</LinearLayout>
【问题讨论】:
标签: android listview android-listview simpleadapter