开发者

onItemClick listener in ListView is not working in TabHost

Listview is located inside the TabActivity and I am unable to generate the click on listItem, try a lot of way but unabl开发者_如何学编程e to accomplish the task, so, anybody can help. thank you.


Taking a new View then inflate it will resolve the problem in listview onClick in TabHost...!

public View getView(final int position, View convertView1, ViewGroup parent) 
{

    final ViewHolder holder;

    final Context context;

    View convertView = null;

    if (convertView == null) 
    {
        convertView = mInflater.inflate(R.layout.file_display_binding, null);                       
        holder = new ViewHolder();
        System.out.println("inside efficient array");                       
        holder.file_imgview = (ImageView)convertView.findViewById(R.id.file_icon_diplay);                                        

        convertView.setOnClickListener(new View.OnClickListener()
        {
            //@Override
            public void onClick(View v) 
            {
            }
        }
    }


}


Firstly, get your ListView from it's ID:

ListView lv = (ListView)findViewById(R.id.myListView);

Then, set its setOnItemClickListener like:

lv.setOnItemClickListener(new OnItemClickListener()
    {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3)
        {
            // TODO Auto-generated method stub

        }
    });


lv.setOnItemClickListener(new OnClickListener()
            {               
                @Override
                public void onClick(View v) 
                {
                    Intent inttentEventDetails = new Intent(Home.this, EventDetails.class);
                    inttentEventDetails.putExtra("EventID", v.getId());
                    overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

                    TabGroupActivity pActivity = (TabGroupActivity)Home.this.getParent();
                    pActivity.startChildActivity("UpcomingEvents", inttentEventDetails);    
                }
            });


You must notice that when a custom ListView contains focusable elements, such as buttons or checkBoxes, the method onListItemClick may not work (I think it's the expected behaviour).

So you must remove the focus from these focusable elements and it shall do the trick. In other words, add the following commands to the focusable elements of your ListView:

android:focusable="false"
android:focusableInTouchMode="false"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜