0

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

这是代码:

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
4

3 回答 3

4

您应该将活动的上下文(通过 put )传递给意图YourActivity.this,通过仅传递this,您正在传递AdapterView.OnItemClickListener()..

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
        @SuppressWarnings("unchecked")                  
        Intent intent = new Intent(YourActivity.this, Profileviewer.class);  
        startActivity(intent); 
    }
});
于 2012-07-30T08:38:50.200 回答
1

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

于 2012-07-30T08:44:08.080 回答
0

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

  1. Intent intent = new Intent({package_name}, Profileviewer.class);
  2. Intent intent = new Intent(Profileviewer.this, Profileviewer.class);
于 2012-07-30T08:43:46.857 回答