如何使用textview显示从列表视图中选择的项目的值 [英] How to display the value of an item selected from a list view using textview
问题描述
使用simplesursoradapter我已经提出了一个listview。我从listview中选择一个项目,并将其保存在变量'titlename'中,并能够在Toast中显示。现在,我希望将'titlename'中的这个值传递给文本视图id'textView3',以便它可以显示在同一活动的屏幕顶部。当我尝试使用以下代码时,我在行 textView.setText(query.toString())中得到一个NULL指针异常;
a)TextView ID'textView'和'textView2'在custom_row.xml中
b)TextView ID'textView3'在Activity_Out.xml中
静态 String v_titlename;
public void onItemClick(AdapterView TextView selectedTitle =(TextView)view.findViewById (R.id.textView);
TextView titlename =(TextView)view.findViewById(R.id.textView2);
TextView textView =(TextView)findViewById(R.id.textView3);
v_titlename = titlename.getText()。toString();
String query = titlename.getText()。toString();
textView .setText(query.toString());
Toast.makeText( this ,titlename.getText(),Toast.LENGTH_LONG)。show();
inputID = selectedTitle.getText()。toString(); // 此标题的_id存储在inputID中
}
你的代码没有意义。检查出来:
1. Android ListView示例 [ ^ ]
2. 使用两个布局xml一个活动的文件 [ ^
Using simplesursoradapter I have raised a listview. I select an item from listview and keep it in a variable 'titlename' and able to show in Toast. Now, I want this value in 'titlename' to be passed to a text view id 'textView3' so that it could be displayed on top of the screen in the same activity. When I tried with the following code I get a NULL pointer exception at line textView.setText(query.toString());
a)TextView ID 'textView' and 'textView2' are in custom_row.xml
b)TextView ID 'textView3' is in Activity_Out.xml
static String v_titlename;
public void onItemClick(AdapterView TextView selectedTitle = (TextView)view.findViewById(R.id.textView);
TextView titlename= (TextView)view.findViewById(R.id.textView2);
TextView textView = (TextView) findViewById(R.id.textView3);
v_titlename=titlename.getText().toString();
String query = titlename.getText().toString();
textView.setText(query.toString());
Toast.makeText(this, titlename.getText() , Toast.LENGTH_LONG).show();
inputID=selectedTitle.getText().toString(); // the _id of this title is stored in inputID
}
You code does not make sense. Check these out:
1. Android ListView Example[^]
2. Using two layout xml file for one Activity[^]
这篇关于如何使用textview显示从列表视图中选择的项目的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!