Android ListView获取所选项目文本

Android ListView获取所选项目文本,android,listview,text,textview,Android,Listview,Text,Textview,我有这个密码 public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) { TextView txt = (TextView)viewClicked.findViewById(R.id.item_topic_name); // text is always null } public void on

我有这个密码

public void onItemClick(AdapterView<?> parent, View viewClicked, 
                       int position, long id) {

    TextView txt = (TextView)viewClicked.findViewById(R.id.item_topic_name);

    // text is always null
}
public void onItemClick(AdapterView父对象,视图已单击,
内部位置,长id){
TextView txt=(TextView)viewClicked.findViewById(R.id.item\u topic\u name);
//文本总是空的
}

item_topic_name是listview项目的textview id,但findviewbyId始终返回null,应用程序崩溃。

要获取seleteditem文本,请使用

((TextView) viewClicked).getText();
而不是

TextView txt = (TextView)viewClicked.findViewById(R.id.item_topic_name);

因为点击的
viewClicked
已经是一个
view
,所以只需将其转换为
TextView
,然后使用
getText()
获取所选项目的文本。

@MarioM很乐意帮忙,不要忘记接受并投票,这样可能会帮助其他有类似问题的人。10分钟后,我才可以选择答案。