您如何创建的实例
ClickableListAdapter?
创建列表适配器时,您必须传递一个资源ID
viewId,它应该是一个资源ID ,
layout稍后会被夸大。
public ClickableListAdapter(Context context, int viewid, List objects) { // Cache the LayoutInflate to avoid asking for a new one each time. mInflater = LayoutInflater.from(context); mDataObjects = objects; mViewId = viewid;下面,代码对传递给构造函数并调用的xml布局进行膨胀
createHolder。
view = mInflater.inflate(mViewId, null); // call the user's implementation holder = createHolder(view);
因此,请确保在实例化您的时
ClickableListAdapter,传递的是
layout而不是
id
编辑 您必须使用以下内容创建一个xml布局,该布局取自您提供的链接:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center_vertical" ><TextView android:text="Text" android:id="@+id/listitem_text" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content" ></TextView> <ImageView android:id="@+id/listitem_icon" android:src="@drawable/globe2_32x32" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxWidth="32px" android:maxHeight="32px" > </ImageView> </LinearLayout>
如果
mylistrow.xml在布局目录中调用它,则将适配器构造为:
adapter = new MyClickableChannelListAdapter(this, R.layout.mylistrow, channelList); setListAdapter(adapter);



