【发布时间】:2011-04-13 12:45:08
【问题描述】:
我需要将描述保存在 ListView 上所选项目的字符串中。
我该怎么做?
【问题讨论】:
标签: android eclipse string listview save
我需要将描述保存在 ListView 上所选项目的字符串中。
我该怎么做?
【问题讨论】:
标签: android eclipse string listview save
如果您有简单的列表项,则必须在 Activity 类中声明 String 变量并注册 itemclick 事件以监听项目的点击。
我就是这样做的:
class YourActivity extends Activity{
String my_selected_item_text=null;
@override
protected void onCreate(Bundle savedInstanceState)
{
//your stuffs here
yourlistview.setOnItemClickListener(
new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long arg3) {
my_selected_item_text=(String)yourlistview.getItemAtPosition(position);
//my_selected_item_text contains description of the String displayed in your ListView. now you can save that description anywhere you want....
});
}
}
【讨论】:
我的第一个想法是,您可以在列表视图中使用您的活动的字符串成员变量
【讨论】: