我有一个 ListView,它显示静态数据和图像(比如 Activity A)。当我单击 ListVoew 项目时,数据被捕获并传递到下一个活动(我们称之为活动 B)。在活动 B 中,我想将选定的值传递到 DB select where 子句并获取数据并显示与选择有关的相关信息。这是我的代码片段...
活动一:
String subproduct = ((TextView) view.findViewById(R.id.product_label)).getText().toString();
// Launching new Activity on selecting single List Item
SharedPreferences sharedPreferences = getSharedPreferences("pref",MODE_WORLD_READABLE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.putString("subproduct", subproduct);
editor.commit();
Intent myIntent = new Intent(getApplicationContext(),Details.class);
startActivity(myIntent);
这是我的活动 B:enter code here
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.details1);
SharedPreferences myPrefs = this.getSharedPreferences("pref", MODE_WORLD_READABLE);
String subproduct = myPrefs.getString("subproduct","null");
TextView txtProduct1 = (TextView) findViewById(R.id.detail_item);
txtProduct1.setText(subproduct);
这是我的DBHelper.java。在这里,我想传递选定的值。请帮助我如何实现这一目标...
public Cursor getData(){
//SharedPreferences myPrefs = this.getSharedPreferences("pref", 0);
//String subproduct = myPrefs.getString("subproduct","null");
Cursor c = myDataBase.rawQuery("SELECT * FROM Destmain WHERE destname= " + ? + " ", null);
while (c.moveToNext()){
DestInfo q = new DestInfo();
q.setDestination(c.getString(1));
q.setCity(c.getString(2));
q.setCountry(c.getString(3));
q.setPeriod(c.getString(4));
q.setType(c.getString(5));
q.setCurrency(c.getString(6));
q.setBriefhistory(c.getString(7));
q.setHighlights(c.getString(8));
}
c.close();
return c;
谁能帮助我如何将 ListView (Activity A) 选择的值传递给获取 DB 数据并在 Activity B 中显示?万分感谢。