【发布时间】:2014-12-01 15:44:42
【问题描述】:
我需要一些帮助。 android编程还是有点新意,不知道能不能做到。
我正在做的事情的要点:我目前正在从 RESTful API 中获取数据,该 API 将数据作为 json 数组返回。我获取数据并将其泵入表格,然后使用适配器并在列表视图中显示所有数据。
数据如下所示(将 x 替换为数据):
[{
id: xxx,
number: "xxxxx",
title: "xxxxxxx",
definition: "xxxxxxx",
status: "xxxxx",
name: "xxxxx"
},
问题来了:从listview中,我想取数据,而onItemSelect,我想把选中的数据插入到一个单独的表中。用户可以选择一个或多个listview,然后从onoptionitemselect中单击一个menuItem,它将数据插入到表中。
我有两个主要问题: 1.我目前在setOnItemClickListener中使用这个代码:
String item = adapterView.getItemAtPosition(position).toString();
它以数组的形式抽出。我可以从数组中解析每个单独的元素吗? (根据数据,我想提取 id、number、title 等数据) 2.我不确定这是否有效,但是在我选择了项目之后,我可以使用 onOptionsItemSelected 菜单项来告诉应用程序将数据插入到新表中吗?
这就是我现在所拥有的:
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
if (id == R.id.menu_favorite){
return true;
}
return super.onOptionsItemSelected(item);
}
感谢您的所有帮助。这是一次很棒的学习经历,我希望能学到更多。
谢谢!
【问题讨论】:
标签: android listview android-sqlite