我正在使用此库:https://github.com/erikwt/PullToRefresh-ListView
我使用自定义适配器实现了PullToRefresh-ListView。结果如下:
我的问题是下一个:我只能点击第一个项目(标题1,描述1),其他项目不起作用。这是我的onClickItem代码:
myAdapter = new ListToRefreshAdapter(this, R.layout.list_item, myItemList);
myList = (PullToRefreshListView) findViewById(R.id.refreshList);
myList.setAdapter(myAdapter);
myList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Context context = view.getContext();
TextView title = (TextView) view.findViewById(R.id.titleItem);
TextView desc = (TextView) view.findViewById(R.id.descItem);
String titleItem = title.getText().toString();
String descItem = desc.getText().toString();
Toast.makeText(context, "Item Title: " + titleItem + ", Item Desc: " + descItem, Toast.LENGTH_SHORT).show();
Log.i("TOUCH EVENT TEST", "OK");
startActivity(new Intent(getApplicationContext(), ItemDetails.class));
}
});
这是我的适配器:
public class ListToRefreshAdapter extends ArrayAdapter<ItemObject> {
protected Context myContext;
protected int resId;
protected ItemObject[] myListdata = null;
protected LayoutInflater myInflater = null;
public ListToRefreshAdapter(Context myContext, int resId, ItemObject[] myListData) {
super(myContext, resId, myListData);
this.myContext = myContext;
this.resId = resId;
this.myListdata = myListData;
myInflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = myInflater.inflate(resId, null);
}
TextView title = (TextView) convertView.findViewById(R.id.titleItem);
TextView desc = (TextView) convertView.findViewById(R.id.descItem);
ImageView imgItem = (ImageView) convertView.findViewById(R.id.imgItem);
ItemObject itemObject = myListdata[position];
title.setText(itemObject.itemTitle);
desc.setText(itemObject.itemDesc);
imgItem.setBackgroundResource(R.drawable.item_no_picture);
return convertView;
}
}
任何人都知道我做错了什么?它是图书馆还是我的实施?
感谢您的回答:)
答案 0 :(得分:0)
我找到了答案。我的ListView在FrameLayout中。我用LinearLayout更改它,它可以工作。
谢谢!