我是android新手这里我遇到问题当我尝试将已恢复的数据从光标传递到捆绑然后我无法获得该变量的值。我的代码请帮助我从这里出来情况。
Cursor cur3 = db3.rawQuery(“SELECT * FROM”+ TableName,null);
try {
db3 = this.openOrCreateDatabase("remoteid.db", MODE_PRIVATE, null);
if(cur3 != null )
{
if(cur3.moveToFirst())
{
do {
valueOfID = cur3.getString(cur3.getColumnIndex("PretestID"));
valuOfDate = cur3.getString(cur3.getColumnIndex("Date"));
textType = cur3.getString(cur3.getColumnIndex("txtVCT"));
valueOfDDLTS = cur3.getString(cur3.getColumnIndex("ddlTestingSession"));
valueOfReason = cur3.getString(cur3.getColumnIndex("txtReason"));
valueOfHowmany = cur3.getString(cur3.getColumnIndex("txthowmany"));
valueOftxtques1 = cur3.getString(cur3.getColumnIndex("txtques1"));
valueOfrblques2a = cur3.getString(cur3.getColumnIndex("rblques2a"));
valueOfrblques2b = cur3.getString(cur3.getColumnIndex("rblques2b"));
valueOfrblques3 = cur3.getString(cur3.getColumnIndex("rblques3"));
valueOftxtques4 = cur3.getString(cur3.getColumnIndex("txtques4"));
valueOfrblques5 = cur3.getString(cur3.getColumnIndex("rblques5"));
valueOfrblques6 = cur3.getString(cur3.getColumnIndex("rblques6"));
valueOfrblques7 = cur3.getString(cur3.getColumnIndex("rblques7"));
valueOfrblques8 = cur3.getString(cur3.getColumnIndex("rblques8"));
valueOfrblques9 = cur3.getString(cur3.getColumnIndex("rblques9"));
valueOfddlsick = cur3.getString(cur3.getColumnIndex("ddlsick"));
valueOftxtques11 = cur3.getString(cur3.getColumnIndex("txtques11"));
valueOfrblques12 = cur3.getString(cur3.getColumnIndex("rblques12"));
valueOftxtques13 = cur3.getString(cur3.getColumnIndex("txtques13"));
valueOftxtques14 = cur3.getString(cur3.getColumnIndex("txtques14"));
valueOfrblques15 = cur3.getString(cur3.getColumnIndex("rblques15"));
valueOfrblques16 = cur3.getString(cur3.getColumnIndex("rblques16"));
valueOfrblques17 = cur3.getString(cur3.getColumnIndex("rblques17"));
valueOftxtques18 = cur3.getString(cur3.getColumnIndex("txtques18"));
//Toast.makeText(getApplicationContext(), valueOftxtques18, Toast.LENGTH_SHORT).show();
}while (cur3.moveToNext());
}
}
}
catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (db3 != null)
db3.close();
}
cur3.close();
arrayadapter11 = new simpleefficientadapter(Screening.this,prtestData);
arrayadapter22 = new simpleefficientadapter(Screening.this,screeningData);
arrayadapter33 = new simpleefficientadapter(Screening.this,postData);
mylist1.setAdapter(arrayadapter11);
mylist1.setOnItemClickListener(this);
mylist2.setAdapter(arrayadapter22);
mylist2.setOnItemClickListener(this);
mylist3.setAdapter(arrayadapter33);
mylist3.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent intent;
switch (arg0.getId()) {
case R.id.prescreenlist:
intent = new Intent(getApplicationContext(), NewScreening.class);
Bundle bundle = new Bundle();
bundle.putString("DateValue", valuOfDate);
bundle.putString("TT", textType);
bundle.putString("idValue", valueOfID);
bundle.putString("ddltsValue", valueOfDDLTS);
bundle.putString("reasonValue", valueOfReason);
bundle.putString("howmanyValue", valueOfHowmany);
bundle.putString("textqus1Value", valueOftxtques1);
bundle.putString("textqus2aValue", valueOfrblques2a);
bundle.putString("textqus2bValue", valueOfrblques2b);
bundle.putString("rbqs3Value", valueOfrblques3);
bundle.putString("rbqs4Value", valueOftxtques4);
bundle.putString("rbqs5Value", valueOfrblques5);
bundle.putString("rbqs6Value", valueOfrblques6);
bundle.putString("rbqs7Value", valueOfrblques7);
bundle.putString("rbqs8Value", valueOfrblques8);
bundle.putString("rbqs9Value", valueOfrblques9);
bundle.putString("ddlsValue", valueOfddlsick);
bundle.putString("tq11Value", valueOftxtques11);
bundle.putString("tq12Value", valueOfrblques12);
bundle.putString("tq13Value", valueOftxtques13);
bundle.putString("tq14Value", valueOftxtques14);
bundle.putString("rbqs15Value", valueOfrblques15);
bundle.putString("rbqs16Value", valueOfrblques16);
bundle.putString("rbqs17Value", valueOfrblques17);
bundle.putString("rbqs18Value", valueOftxtques18);
intent.putExtras(bundle);
startActivityForResult(intent, 1);
setResult(1,intent);
break;
答案 0 :(得分:1)
更明智的举动,可能是将该数据库行的id传递给下一个Activity。
您的代码不完整,但看起来只有最后一行的数据才会传递给下一个活动。
此外,如果你只是将theExtra直接放入intent而不是中间的Bundle,它可能会更加有效和清晰。
好的做法是将包名称作为额外名称中的前缀。