Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not Getting OnItemClick Event of ListView

I'm using one custom listview . When I'm click on listview I didn't getting onClick Event .

Here is my code .

        lvlList = (ListView)findViewById(R.id.lvlList);
        lvlList.setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView<?> a, View v,int position, long id) 
            {
                Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show();
            }
        });

lvlList.setAdapter(new OrderAdapter(getBaseContext()));

OrderAdapter

private class OrderAdapter extends BaseAdapter
{
    private LayoutInflater mInflater;

    public OrderAdapter(Context context) 
    {
        mInflater = LayoutInflater.from(context);
    }

    public View getView(int position, View convertView, ViewGroup parent) 
    {
        ViewHolder holder;

        if (convertView == null) 
        {
            convertView = mInflater.inflate(R.layout.example, null);
            holder = new ViewHolder();

            holder.txtTest = (TextView) convertView.findViewById(R.id.txtTest);

            convertView.setTag(holder);
        } 
        else 
        {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txtTest.setText(Util.SampleTest.get(position));
                    return convertView;
    }

    public class ViewHolder 
    {
        public TextView txtTets;
    }

    public int getCount(){return Util.SampleTest.size();}

    public Object getItem(int position){return position;}

    public long getItemId(int position){return position;}
}
like image 550
Chirag Avatar asked Mar 15 '11 12:03

Chirag


1 Answers

You need to set android:descendantFocusability="blocksDescendants" in your custom xml layout file for the LinearLayout or whatever layout you've been using. (for defining your custom row)

That should solve your problem.Because it did solve mine.If it solves kindly mark my post as your answer.

You can also refer the comments here

like image 82
Nezam Avatar answered Sep 20 '22 19:09

Nezam