开发者

listview onitem clicklistener not responding always

I am using the below code.

    listView = (ListView) findViewById(R.id.SkiiplistListView);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position,
                long arg3) {
            // TODO Auto-generated method stub
            System.out.println("--position--"+position);
            Intent intent = new Intent(SkiipListScreen.this, SkiiperProfileScreen.class);
            Bundle bundle = new Bundle();
            bundle.putString("uid", uid);
            intent.putExtras(bundle);
            startActivity(intent);
        }

    });

I have also tried the below.

   listView = (ListView) findViewById(R.id.SkiiplistListView);
   listView.setOnItemClickListener(this);

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

    System.out.println("--position--"+position);
    Intent intent = new Intent(this, SkiiperProfileScreen.class);
    Bundle bundle = new Bundle();
    bundle.putString("uid", uid);
    i开发者_JS百科ntent.putExtras(bundle);
    startActivity(intent);

    }

I have used this kind of code in many classes. But in some classes this code responds and in some it doesn't. In many cases after some time it starts responding after some time.

I don't know why it is so inconsistent. Please if you have any answer, let me know.


What you're saying seems to be impossibl.

   listView.setOnItemClickListener(new OnItemClickListener()...

always works.

Check for the single cell layout XML you are using in the adapter to get a view for the list and ensure that the elements you fill in this are not clickable. It will prevent listitem to be clicked. Check the XML code. I think this should resolve the problem


You don't show your layout XML, but do you have other focusable objects in the listview? For example, check boxes, or edit texts? You'll find that these objects will steal touch events from the listitem. Visually, it looks like the listitem has responded, but the touch event is sent to the check box.

If this is the case, it's a simple matter to handle - just call setFocusable (false) for the check box (or edit text, etc).

Of course, this means you'll need to handle the touch events for that object yourself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜