Android Bundle Concept to pass deta between activities
I am new to android here i am facing problem when i try to pass the retrived data from curser to bundle then i am not able to get the value of that variable.Below is my code please help me to come out from this situation.
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"));
val开发者_Python百科uOfDate = 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;
A wiser move, might be passing the id of that database row to the next Activity.
And your code is incomplete, but it looks like only the last row's data will ever be passed to the next activity.
Also, it might be mildly more efficient and clear if you just putExtra directly into the intent instead of the intermediary Bundle.
Good practices said to include the package name as a prefix in the extra names.
精彩评论