0

thanks for reading this and helping I appreciate it! In one of my android activities I have a custom list and it works great, this is the xml for it

<?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>

I use it in my activity like this

MemberListObjectAdapter adapter = new MemberListObjectAdapter(Brothers.this, 
                            R.layout.listview_item_row,   memberListObject_data);

                    listView1.setAdapter(adapter);

and this is my Adapter class

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

}

in my activity I would like to have an onListItemClick method or something similar to this

protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

}

so i would be able to click on my list items and do something with them, In previous activities the above method worked for me but i think because this is a custom list it is not working now. at the moment the line "super.onListItemClick(l,v,position,id);" the onListItemClick is underlined and it says "The method onListItemClick(ListView, View, int, long) is undefined for the type Activity". So my question is, How can I work with my code to make my list items clickable? Thank you! I really appreciate any help

  • 1. If your activity extends from ListActivty, override onListItemClick () method; 2. If not, set OnItemClickListener to your listview – handrenliang May 17 '14 at 01:50
  • Thank you handrenliang! that was such an easy thing, just setting an onItemClickListener to my listview. I really appreciate the help! – user3627609 May 17 '14 at 01:57
  • try [This](http://stackoverflow.com/questions/20208285/listview-itemclick-not-work/20208788#20208788) code in your inflator..i hope it will help you.!! – Pankaj Arora May 17 '14 at 04:15

0 Answers0