Question

I am using this library : https://github.com/erikwt/PullToRefresh-ListView

I implement my PullToRefresh-ListView with my custom Adapter. Here is the result :

enter image description here

My problem is the next : I can only click on the first item (Title 1, Description 1), the others doesn't work. Here is my code for the 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));
        }
    });

Here is my adapter :

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;
}
}

Anybody has an idea of what I'm doing wrong ? Is it the library or my implementation ?

Thank you for answers :)

Was it helpful?

Solution

I found the answer. My ListView was in a FrameLayout. I change it with a LinearLayout and it works.

Thank you !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top