开始新的意图

时间:2012-07-30 08:37:17

标签: android listview android-intent

我试图开始点击列表视图中的项目的新意图,但不知道如何使其正常工作。

以下是代码:

final ListView lv = getListView();
lv.setTextFilterEnabled(true);  
lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            @SuppressWarnings("unchecked")                  
            Intent intent = new Intent(this, Profileviewer.class);  
            startActivity(intent); 
        }
});

我在new Intent(this, Profileviewer.class);

上收到了编译错误
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<Profileviewer>) is undefined

3 个答案:

答案 0 :(得分:4)

你应该传递活动的上下文(通过放置YourActivity.this),只传递这个,你传递{{1 }} ..

AdapterView.OnItemClickListener()

答案 1 :(得分:1)

我想你忘了在AndroidManifest.xml中添加一个新活动。

答案 2 :(得分:0)

正如您所说,您正尝试从ListView启动Intent。在您的代码中,这意味着列表视图。这就是错误信息所说的内容。您需要使用以下任何一种方法来使用您的包名称。

  1. Intent intent = new Intent({package_name}, Profileviewer.class);
  2. Intent intent = new Intent(Profileviewer.this, Profileviewer.class);
相关问题