感谢您阅读本文并帮助我欣赏它! 在我的一个Android活动中,我有一个自定义列表,它工作得很好,这是它的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="15dp"/>
<TextView android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
</LinearLayout>
我在我的活动中使用它
MemberListObjectAdapter adapter = new MemberListObjectAdapter(Brothers.this,
R.layout.listview_item_row, memberListObject_data);
listView1.setAdapter(adapter);
这是我的Adapter类
public class MemberListObjectAdapter extends ArrayAdapter<MemberListObject>{
Context context;
int layoutResourceId;
MemberListObject data[] = null;
public MemberListObjectAdapter(Context context, int layoutResourceId, MemberListObject[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
WeatherHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new WeatherHolder();
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
row.setTag(holder);
}
else
{
holder = (WeatherHolder)row.getTag();
}
MemberListObject memberListObject = data[position];
holder.txtTitle.setText(memberListObject.title);
holder.imgIcon.setImageResource(memberListObject.icon);
return row;
}
static class WeatherHolder
{
ImageView imgIcon;
TextView txtTitle;
}
}
在我的活动中,我希望有一个onListItemClick方法或类似于此
的方法protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
所以我可以点击我的列表项并对它们做一些事情,在以前的活动中,上面的方法对我有用,但我认为因为这是一个自定义列表,它现在不起作用。此刻的行“super.onListItemClick(l,v,position,id);” onListItemClick带有下划线,它表示“类型为Activity”的方法onListItemClick(ListView,View,int,long)未定义。所以我的问题是,我如何使用我的代码使我的列表项可以点击?谢谢!我真的很感激任何帮助