setOnItemClickListener

setOnItemClickListener

本文介绍了Android的setOnItemClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够启动 OnItemClickListener

您可以看到我的code段

You can see my code snippet

 ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, new String[] { "title"}, new int[] { R.id.item_title});
    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
            Toast.makeText(TopNewsActivity.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_LONG).show();

        }
    });

在setListAdapter后,我的调试器去的 lv.setOnItemClickListener 但当时并没有进入循环并移出。

after the setListAdapter my debugger goes to "lv.setOnItemClickListener" but then does not get into the loop and moves out.

我想使可点击的链接好心帮。

I want to make the links Clickable kindly help.

推荐答案

也许你忘了公共无效onItemClick之前写@覆盖?

Maybe you forgot to write @Override before public void onItemClick?

Adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
        }
});

这篇关于Android的setOnItemClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:16