我已经厌倦了所有现有的答案,但没有一个能满足我的需求。基本上我从本地数据库填充了listView
。我只想让节目中的选定值到textView
例如:
如果用户选择" Vaccine"来自list-view
,我想要" Vaccine"出现在TextView
。我到目前为止尝试过的代码之一是
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
TextView tv = (TextView) findViewById(R.id.textView1);
String str = parent.getItemAtPosition(position).toString();
tv.setText(str);
}
上面的代码给了我android.database.sqlite.SQLiteCursor@4274b148
。但我需要存储&#34; Vaccine&#34;。
填充列表视图的代码
private void populateListViewAppTypeFromDB()
{
// TODO Auto-generated method stub
Cursor cursor = dbmanager.getAllAppTypeRows();
String[] fromFieldNames = new String[] {NewDatabaseManager.KEY_TYPEOFAPPLIANCE};
int[] toViewIds = new int[] {R.id.appTypeNamefield};
@SuppressWarnings("deprecation")
SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter
(
this,
R.layout.item_layout_app_type,
cursor,
fromFieldNames,
toViewIds
);
ListView myAppTypeList = (ListView) findViewById (R.id.appTypeListFromDatabase);
myAppTypeList.setAdapter(myCursorAdapter);
}