【问题标题】:ListView pull to refresh, I can only click on the first item, why?ListView拉刷新,我只能点击第一项,为什么?
【发布时间】:2014-04-29 12:36:28
【问题描述】:

我正在使用这个库: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;
}
}

有人知道我做错了什么吗?是图书馆还是我的实现?

感谢您的回答:)

【问题讨论】:

    标签: android listview android-listview pull-to-refresh


    【解决方案1】:

    我找到了答案。我的 ListView 在 FrameLayout 中。我用 LinearLayout 对其进行了更改,它可以工作。

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-13
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多