我有一个自定义数组适配器,我想在ListView中有一个图像视图。 这只发生在2.2和2.3.X设备上。ListView与图像
我行模板是如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/place_category_icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp"
android:background="@drawable/photo1"
android:scaleType="centerCrop" >
</ImageView>
<TextView
android:id="@+id/place_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/list_timestamp"
android:ellipsize="end"
android:singleLine="true"
android:text="Harsha Mallikarjun Vantagudi"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/place_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="6dp"
android:paddingLeft="30dp"
android:singleLine="true"
android:text="2 hours" >
</TextView>
</LinearLayout>
当我加载列表。图像被显示,但当我尝试滚动文本随机再现并消失时,文本消失。
适配器
public class PlacesListAdapter extends ArrayAdapter<Place> implements
Filterable {
public Context context;
private List<Place> places;
public PlacesListAdapter(Context context, List<Place> places) {
super(context, R.layout.list_item_place, places);
this.context = context;
this.places = places;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater;
inflater = LayoutInflater.from(getContext());
view = inflater.inflate(R.layout.list_item_place, null);
}
Place place = places.get(position);
if (place != null) {
TextView place_title = (TextView) view
.findViewById(R.id.place_name);
TextView place_distance = (TextView) view
.findViewById(R.id.place_distance);
if (place_title != null) {
place_title.setText(place.getPlaceName());
}
if (place_distance != null) {
place_distance.setText(place.getPlaceDistance());
}
}
return view;
}
}
不错的截图,但是有些代码呢? –
@ K-ballo补充说明。如果我删除图像,它工作正常。 –
我不知道我在做什么,但Iam没有在getView中使用inflatter,我没有问题...也许值得一试 – 2012-12-24 19:30:09