我已经实现了一个自定义SimpleCursorAdapter
,以便将图像和文本插入到 myListView
中,但是当用户滚动时图像会四处移动。我怎样才能让他们留在原地?这是我的代码(为简单起见,我将其剥离):
final class mySimpleCursorAdapter extends SimpleCursorAdapter {
public mySimpleCursorAdapter(Context context, int layout, Cursor cur,
String[] from, int[] to) {
super(context, layout, cur, from, to);
mContext = context;
mLayoutInflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mLayoutInflater.inflate(R.layout.row, parent, false);
return v;
}
@Override
public void bindView(View v, Context context, Cursor c) {
ImageView bar11 = (ImageView) v.findViewById(R.id.bar);
ImageView bar12 = (ImageView) v.findViewById(R.id.bar2);
ImageView bar13 = (ImageView) v.findViewById(R.id.bar3);
TextView sign = (TextView) v.findViewById(R.id.text3);
sign.setText(currency);
if (someValue == 0){
bar11.setVisibility(View.GONE);
}
if (someValue == 1){
bar12.setVisibility(View.VISIBLE);
}
if (someValue == 2){
bar13.setVisibility(View.VISIBLE);
}
}
}
行.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bar"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:background="@drawable/greenbar"/>
<ImageView
android:id="@+id/bar2"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:background="@drawable/two"/>
<ImageView
android:id="@+id/bar3"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:background="@drawable/two"/>
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
列表.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/expense"
android:background="@drawable/expensebackgroundblue">
<ListView
android:id="@+id/contentlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000"
android:cacheColorHint="#00000000" >
</ListView>
</RelativeLayout>