我使用ListView
生成了一次刷卡SimpleAdapter
(我已使用com.fortysevendeg.swipelistview.SwipeListView
生成ListView
)。我已经完成了以下内容。当我滑动ListView
时,前面的布局会突出显示为黑色,并且ImageView的颜色会变为橙色。当我在ListView中只有一行时,它工作正常。但是我注意到当有多行时,无论哪一行被点击,拉斯特罗都会突出显示为黑色。任何人都可以一步一步告诉我如何解决这个问题。我想继续SimpleAdapter
本身,但也欢迎任何其他解决方案。我的代码如下。请仔细阅读。
public class mycontacts extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.mycontacts_activity, container,
false);
final SwipeListView swipy=(SwipeListView)view.findViewById(R.id.swipy);
SimpleAdapter k=new SimpleAdapter(getActivity(),val,R.layout.contact2,new String[]{"name","path","id"},new int[]{R.id.example_itemname,R.id.path,R.id.contactid})
{
@Override
public View getView (int position, View convertView, ViewGroup parent)
{
final RelativeLayout l=(RelativeLayout)v.findViewById(R.id.front);
swipy.setSwipeListViewListener(new BaseSwipeListViewListener(){
@Override
public void onClickFrontView(int position) {
// TODO Auto-generated method stub
super.onClickFrontView(position);
l.setBackgroundColor(Color.BLACK);
}
@Override
public void onStartOpen(int position, int action, boolean right) {
// TODO Auto-generated method stub
super.onStartOpen(position, action, right);
}
});
return v;
}
};
swipy.setAdapter(k);
return view;
}
contact2.xml文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/back"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@android:color/white"
android:tag="back" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="68dp"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:background="@color/purple"
android:clickable="true"
android:scaleType="centerInside"
android:src="@android:drawable/btn_star" />
</LinearLayout>
<RelativeLayout
android:id="@+id/front"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="@android:color/white"
android:orientation="vertical"
android:tag="front" >
<TextView
android:id="@+id/example_itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/path"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/example_image"
android:text="hiii"
android:textColor="@android:color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/example_itemname"
android:layout_alignParentTop="true"
android:text="path"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="invisible" />
<TextView
android:id="@+id/contactid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/example_image"
android:layout_alignParentTop="true"
android:text="Id"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone" />
</RelativeLayout>
</FrameLayout>
mycontacts_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="@+id/mycontacts_id"
android:layout_height="match_parent">
<com.fortysevendeg.swipelistview.SwipeListView
android:id="@+id/swipy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
swipe:swipeFrontView="@+id/front"
swipe:swipeBackView="@+id/back"
swipe:swipeMode="right"
/>
</LinearLayout>