在android中的listview上的监听器

时间:2013-01-24 10:27:10

标签: android listview listener

 ListView lv=(ListView) findViewById(android.R.id.list);
         lv.setOnItemLongClickListener(new OnItemLongClickListener()//error:change to <listeners>
{
             public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int row, long arg3) {

                //here is where i got the classCastException.
                String[] tmp = (String[]) arg0.getItemAtPosition(row);

                //tmp[0] ist the Text of the first TextView displayed by the  clicked ListItem 
                Toast.makeText(ReminderListActivity.this, tmp[0].toString(), Toast.LENGTH_SHORT).show();

                return true;
             }
         });

3 个答案:

答案 0 :(得分:0)

更改为lv.setOnItemClickListener

答案 1 :(得分:0)

您需要修复进口 你可能导入错误的类,现在eclipse认为你想要别的东西。

答案 2 :(得分:0)

你应该使用下面的监听器:

m_listView.setOnItemClickListener(new OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> p_arg0, View p_arg1, int p_arg2, long p_arg3)
        {
            // TODO Auto-generated method stub
        }
    });