我已经完成了以下编码,用于从数据库中检索数据,并希望在“编辑文本”视图中显示另一个活动。以下代码用于获取数据..
String fetch_data(int id) {
SQLiteDatabase sq = this.getReadableDatabase();
String q = "SELECT "+TAB_NAME+" FROM "+TABLE_NAME+" WHERE "+TAB_ID+" = "+id;
Cursor c = sq.rawQuery(q, null);
String s = "";
c.moveToFirst();
if (c.moveToFirst()) {
s = c.getString(c.getColumnIndex(TAB_NAME+""));
}
return s;
}
以下代码用于显示此活动中的数据..
t1 = (EditText) findViewById(R.id.editText);
final MyDBFunction obj = new MyDBFunction(getApplicationContext());
int req_pos = getIntent().getIntExtra("MyKEY",999);
t1.setText(obj.fetch_data(req_pos+1));
t1.setSelection(t1.getText().length());
此代码来自我试图获取数据的活动..
l = (ListView)findViewById(R.id.listView);
MyDBFunction mf = new MyDBFunction(getApplicationContext());
final String[] data = mf.broadData();
l.setAdapter(new ArrayAdapter(getApplicationContext(),R.layout.lvlayout,R.id.text1,data));
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),"Clicked On "+data[position],Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(),ShowInfo.class);
i.putExtra("MyKEY",position);
startActivity(i);
}
});
但我无法获得数据在哪里?
答案 0 :(得分:0)
您的SQLite数据库存储在哪里?可能它是在第一个活动的私人存储中?
也许你可以看看: https://developer.android.com/guide/topics/data/data-storage.html