Android 下一步和后退按钮的编码
在这段代码中,我通过单击“上一步”和“下一步”按钮从本地数据库中检索表名,逐个匹配表名来显示问题。最初,当我按下“下一步”按钮时,它工作正常并正确显示所有问题,同时按下“后退”按钮时,它也工作正常,但当我按下“下一步”,然后再次按下“后退”按钮时,它显示的是下一个索引的问题,而不是上一个索引的问题Android 下一步和后退按钮的编码,android,sqlite,Android,Sqlite,在这段代码中,我通过单击“上一步”和“下一步”按钮从本地数据库中检索表名,逐个匹配表名来显示问题。最初,当我按下“下一步”按钮时,它工作正常并正确显示所有问题,同时按下“后退”按钮时,它也工作正常,但当我按下“下一步”,然后再次按下“后退”按钮时,它显示的是下一个索引的问题,而不是上一个索引的问题 public void compareTableName() { Cursor c=db.getQuestionnum(username,surveyName,sel
public void compareTableName()
{
Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(tablename.equals("email"))
{
selectedTableName=tablename;
Log.e("table",selectedTableName);
i_email=0;
if(c.moveToPosition(i_email))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
next_email++;
back_email=-1;
i_email++;
//counter_email=1;
}
Bundle emailBundle=new Bundle();
emailBundle.putInt("questionnum",question_no);
emailBundle.putString("username",username);
emailBundle.putString("surveyname",surveyName);
emailBundle.putString("quesname",selectedQues);
EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
emailFrag.setArguments(emailBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout,emailFrag, "email");
transaction.commit();
}
if(tablename.equals("numerictext"))
{
selectedTableName=tablename;
Log.e("table",selectedTableName);
i_numeric=0;
back_numeric=-1;
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(c.moveToPosition(i_numeric))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
next_numeric++;
i_numeric++;
//counter_numeric=1;
}
Bundle numericBundle=new Bundle();
numericBundle.putInt("questionnum",question_no);
NumericFragment numericFrag=new NumericFragment();//create the fragment instance for the top fragment
numericFrag.setArguments(numericBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout,numericFrag, "numeric");
transaction.commit();
}
else if(tablename.equals("signature"))
{
selectedTableName=tablename;
Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside signature text","inside");
i_signature=0;
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(c.moveToPosition(i_signature))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
next_signature++;
i_signature++;
//counter_sign=1;
}
Bundle signatureBundle=new Bundle();
signatureBundle.putInt("questionnum",question_no);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
CaptureSignature signatureFrag=new CaptureSignature();
signatureFrag.setArguments( signatureBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("information"))
{
selectedTableName=tablename;
Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside signature text","inside");
i_information=0;
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(c.moveToPosition(i_information))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
next_info++;
i_information++;
//counter_info=1;
}
Bundle informationBundle=new Bundle();
informationBundle.putInt("questionnum",question_no);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
InformationFragment informationFrag=new InformationFragment();
informationFrag.setArguments(informationBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
}
@SuppressLint("NewApi")
@Override
public void onClick(View v)
{
if(v.getId()==R.id.next)
{
i++;
nextButton++;
backcounter--;
Log.e("nextbutton",""+nextButton);
Log.e("value of i",""+i);
Toast.makeText(this,tablename+i,Toast.LENGTH_LONG).show();
cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
counter_info=0;
counter_numeric=0;
counter_sign=0;
counter_email=0;
if(cursor.moveToPosition(i))
{
tablename=cursor.getString(0);
Log.e("inside click",tablename);
//Toast.makeText(this,tablename,Toast.LENGTH_LONG).show();
}
Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(tablename.equals("numerictext"))
{
selectedTableName=tablename;
tableLastClicked=selectedTableName;
Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside numerci text","inside");
Log.e("value","before"+i_numeric);
counter_info=1;
//next_numeric=0;
//next_numeric++;
//if(backcounter!=1)
//{
if(i_numeric==-1)
i_numeric=0;
if(tableBackClicked.equals("numerictext"))
{
i_numeric++;
tableBackClicked="";
}
/*else
i_numeric++;
}
else
{
i_numeric=next_numeric;
}
//counter=0;
/*if(counter_numeric!=1)
{
if(i_numeric>=1)
{
i_numeric++;
}
}
if(counter_numeric==1)
{
i_numeric++;
counter_numeric=0;
}*/
if(c.moveToPosition(i_numeric))
{
//if(i_numeric==0)
i_numeric++;
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
Toast.makeText(this,"question no is"+question_no,Toast.LENGTH_SHORT);
}
Log.e("value numeric","after"+i_numeric);
Bundle numericBundle=new Bundle();
numericBundle.putString("username",username);
numericBundle.putString("surveyname",surveyName);
numericBundle.putString("quesname",selectedQues);
numericBundle.putInt("questionnum",question_no);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
NumericFragment numericFrag=new NumericFragment();
numericFrag.setArguments( numericBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("signature"))
{
selectedTableName=tablename;
tableLastClicked=selectedTableName;
Toast.makeText(getBaseContext(), "last clicked"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside signature text","inside");
Log.e("value sign","before"+i_signature);
//back_signature=-1;
//if(backcounter!=1)
//{
if(i_signature==-1)
i_signature=0;
if(tableBackClicked.equals("signature"))
{
i_signature++;
tableBackClicked="";
}
/*else
next_signature++;
}
else
{
i_signature=next_signature;
}
//counter=0;
/*if(counter_sign!=1)
{
if(i_signature>=1)
{
i_signature++;
}
}
if(counter_sign==1)
{
i_signature++;
counter_sign=0;
}*/
Log.e("value sign","before"+i_signature);
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
//counter_sign=1;
if(c.moveToPosition(i_signature))
{
//if(i_signature==0)
i_signature++;
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
}
Bundle signatureBundle=new Bundle();
signatureBundle.putInt("questionnum",question_no);
signatureBundle.putString("username",username);
signatureBundle.putString("surveyname",surveyName);
signatureBundle.putString("quesname",selectedQues);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
CaptureSignature signatureFrag=new CaptureSignature();
signatureFrag.setArguments( signatureBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("information"))
{
selectedTableName=tablename;
tableLastClicked=selectedTableName;
Toast.makeText(getBaseContext(), " last click"+tableLastClicked, Toast.LENGTH_SHORT).show();
Log.e("inside information text","inside");
Log.e("i_information","before"+i_information);
Log.e("value info","before"+i_information);
//counter_info=1;
//Log.e("backcounter",""+backcounter);
//next_info++;
//back_info=-1;
//if(backcounter!=1)
//{
if(i_information==-1)
i_information=0;
if(tableBackClicked.equals("information"))
{
i_information++;
tableBackClicked="";
}
/*else
i_information++;
}
else
{
i_information=next_info;
}
/*if(counter_info!=1)
{
if(i_information>1)
{
i_information++;
}
}
if(counter_info==1)
{
i_information++;
counter_info=0;
}*/
//db.open();
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(c.moveToPosition(i_information))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
//if(i_information==0)
i_information++;
}
Log.e("value info","after"+i_information);
Bundle informationBundle=new Bundle();
informationBundle.putInt("questionnum",question_no);
informationBundle.putString("username",username);
informationBundle.putString("surveyname",surveyName);
informationBundle.putString("quesname",selectedQues);
InformationFragment informationFrag=new InformationFragment();
informationFrag.setArguments(informationBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("email"))
{
selectedTableName=tablename;
tableLastClicked=selectedTableName;
Log.e("table",tableLastClicked);
Log.e("value email","before"+i_email);
/*if(backn==1)
{
i_email++;
}*/
//e=-1;
/*back_email=-1;*/
next_email=0;
next_email++;
//Log.e("e",""+e);
//Log.e("counter inside email",""+counter);
/*if(counter!=1)
{
Log.e("incounter","");*/
if(i_email==-1)
{
i_email=0;
}
if(tableBackClicked.equals("email"))
{
i_email++;
tableBackClicked="";
}
/*else
{
Log.e("else","");
i_email++;
}
}
/*if(counter==1)
{
i_email=next_email1;
}*/
//Log.e("e1",""+e1);
/*if(e1!=-1)
{
i_email++;
}*/
//counter=0;
/*if(counter_email!=1)
{
if(i_email>1)
{
i_email++;
}
}*/
//counter_email=1;
/*if(counter_email==1||i_email==2)
{
i_email++;
}*/
//db.open();
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
if(c.moveToPosition(i_email))
{
//if(i_email==0)
i_email++;
Log.e("inside","email table");
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
}
Log.e("value email","after"+i_email);
Bundle emailBundle=new Bundle();
emailBundle.putInt("questionnum",question_no);
emailBundle.putString("username",username);
emailBundle.putString("surveyname",surveyName);
emailBundle.putString("quesname",selectedQues);
EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
emailFrag.setArguments(emailBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
transaction.commit();
}
c.close();
}
else
{
i--;
backcounter++;
nextButton--;
Log.e("backcounter",""+backcounter);
Log.e("value of i",""+i);
Toast.makeText(this,""+i,Toast.LENGTH_LONG).show();
cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
if(cursor.moveToPosition(i))
{
tablename=cursor.getString(0);
Log.e("inside click",tablename);
Toast.makeText(this,tablename,Toast.LENGTH_LONG).show();
}
Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
Toast.makeText(this,"value of curosr"+c.getCount(),Toast.LENGTH_SHORT).show();
if(tablename.equals("numerictext"))
{
selectedTableName=tablename;
Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside numerci text","inside");
Toast.makeText(this,"inside numeric text",Toast.LENGTH_SHORT).show();
Log.e("value i","before"+i_numeric);
//Log.e("back numeric",""+back_numeric);
/*if(counter_numeric!=1)
{
back_numeric++;
}
if(back_numeric==0)
{
i_numeric=next_numeric;
}
else*/
Log.e("table last clicked",tableLastClicked);
if(tableLastClicked.equals("numerictext"))
{
i_numeric=i_numeric-2;
tableLastClicked="";
}
else
i_numeric--;
back_numeric=0;
//next_numeric--;
/*if(counter_numeric!=0)
{
i_numeric--;
}*/
Log.e("value i","after"+i_numeric);
if(c.moveToPosition(i_numeric))
{
Toast.makeText(this,"inside numeric text"+i_numeric,Toast.LENGTH_SHORT).show();
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
//counter_numeric++;
//Log.e("count","before"+counter_numeric);
}
Bundle numericBundle=new Bundle();
numericBundle.putString("username",username);
numericBundle.putString("surveyname",surveyName);
numericBundle.putString("quesname",selectedQues);
numericBundle.putInt("questionnum",question_no);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
NumericFragment numericFrag=new NumericFragment();
numericFrag.setArguments( numericBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("signature"))
{
selectedTableName=tablename;
Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside signature text","inside");
Log.e("table last clicked",tableLastClicked);
if(tableLastClicked.equals("signature"))
{
i_signature=i_signature-2;
tableLastClicked="";
}
else
i_signature--;
back_signature=0;
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
Log.e("value i","before"+i_signature);
/*if(counter_sign!=0)
{
i_signature--;
}*/
/*if(counter_sign!=1)
back_signature++;
if(back_signature==0)
{
i_signature=next_signature;
}
else
i_signature--;
next_sign=i_signature;*/
Log.e("value i","after"+i_signature);
if(c.moveToPosition(i_signature))
{
Toast.makeText(this,"inside signature"+i_signature,Toast.LENGTH_SHORT).show();
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
//counter_sign++;
Log.e("count","sign"+counter_sign);
}
Bundle signatureBundle=new Bundle();
signatureBundle.putInt("questionnum",question_no);
signatureBundle.putString("username",username);
signatureBundle.putString("surveyname",surveyName);
signatureBundle.putString("quesname",selectedQues);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
CaptureSignature signatureFrag=new CaptureSignature();
signatureFrag.setArguments( signatureBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("information"))
{
selectedTableName=tablename;
tableBackClicked=selectedTableName;
Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
Log.e("inside info text","inside");
Log.e("value i","before"+i_information);
//if(counter_info!=0)
Log.e("table last clicked",tableLastClicked);
if(tableLastClicked.equals("information"))
{
i_information=i_information-2;
tableLastClicked="";
}
else
i_information--;
back_info=0;
//db.open();
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
/*if(counter_info!=1)
{
back_info++;
}
if(back_info==0)
{
i_information=next_info;
}
else
i_information--;
next_info--;
Log.e("next_info",""+next_info);*/
Log.e("value i","after"+i_information);
/*Log.e("valuebackinfo",""+back_info);
next_information=i_information;*/
if(c.moveToPosition(i_information))
{
Toast.makeText(this,"inside information"+i_information,Toast.LENGTH_SHORT).show();
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no"," "+question_no);
}
Bundle informationBundle=new Bundle();
informationBundle.putInt("questionnum",question_no);
informationBundle.putString("username",username);
informationBundle.putString("surveyname",surveyName);
informationBundle.putString("quesname",selectedQues);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
InformationFragment informationFrag=new InformationFragment();
informationFrag.setArguments(informationBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("email"))
{
selectedTableName=tablename;
tableBackClicked=selectedTableName;
Log.e("table",selectedTableName);
//db.open();
//Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
Log.e("value of curosr",""+c.getCount());
Log.e("value i","before"+i_email);
//Log.e("e back",""+e);
//e1=-1;
//Log.e("e1",""+e);
//e1++;
//Log.e("e1",""+e);
//backn=1;
/*e++;
if(e==0)
{
i_email--;
}
if(counter_email!=0)
i_email--;*/
Log.e("before",""+i_email);
/*if(counter_email!=1)
{
back_email++;
}
if(back_email==0)
{
i_email=next_email;
}
else*/
//back_email++;
//Log.e("back_email",""+back_email);
Log.e("table last clicked",tableLastClicked);
if(tableLastClicked.equals("email"))
{
i_email=i_email-2;
tableLastClicked="";
}
else
i_email--;
back_email=0;
//Log.e("after",""+next_email);
Log.e("value i","after"+i_email);
if(c.moveToPosition(i_email))
{
Log.e("inside","email table");
Toast.makeText(this,"inside email"+i_email,Toast.LENGTH_SHORT).show();
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
Log.e("question_no of email"," "+question_no);
//counter_email++;
//Log.e("counter","email"+counter_email);
}
Bundle emailBundle=new Bundle();
emailBundle.putInt("questionnum",question_no);
emailBundle.putString("username",username);
emailBundle.putString("surveyname",surveyName);
emailBundle.putString("quesname",selectedQues);
EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
emailFrag.setArguments(emailBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
transaction.commit();
}
c.close();
}
}
}实现这一点
@Override
public void onBackPressed() {
if (currentFragment instanceof IBackListener) {
if (((IBackListener) currentFragment).onBackPressed())
return;
}
FragmentManager manager = getSupportFragmentManager();
if (manager.getBackStackEntryCount() > 1) {
resetActionBar();
manager.popBackStack();
return;
}
if (getIntent().getBooleanExtra(SHOW_TOAST_ON_BACK, true)) {
if (lastBackPressed + 3000 > System.currentTimeMillis())
finish();
else {
if (!mNavLayout.isOpen() && slidingPaneEnabled)
mNavLayout.openPane();
lastBackPressed = System.currentTimeMillis();
Toast.makeText(this, "Press back again to exit", Toast.LENGTH_SHORT).show();
}
} else {
if (!mNavLayout.isOpen() && slidingPaneEnabled)
mNavLayout.openPane();
else
finish();
}
}
这是我问题的答案
public void getTableName()
{
cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
lastques=cursor.getCount();
if(cursor.moveToPosition(i))
{
tablename=cursor.getString(0);
}
cursor.close();
}
@SuppressLint("NewApi")
public void compareTableName()
{
Cursor c=db.getQuestionnum(username,surveyName,selectedQues);
j=0;
if(tablename.equals("email"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle emailBundle=new Bundle();
emailBundle.putInt("questionnum",question_no);
emailBundle.putString("username",username);
emailBundle.putString("surveyname",surveyName);
emailBundle.putString("quesname",selectedQues);
EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
emailFrag.setArguments(emailBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout,emailFrag, "email");
transaction.commit();
}
if(tablename.equals("numerictext"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle numericBundle=new Bundle();
numericBundle.putInt("questionnum",question_no);
numericBundle.putString("username",username);
numericBundle.putString("surveyname",surveyName);
numericBundle.putString("quesname",selectedQues);
NumericFragment numericFrag=new NumericFragment();//create the fragment instance for the top fragment
numericFrag.setArguments(numericBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout,numericFrag, "numeric");
transaction.commit();
}
else if(tablename.equals("signature"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle signatureBundle=new Bundle();
signatureBundle.putInt("questionnum",question_no);
signatureBundle.putString("username",username);
signatureBundle.putString("surveyname",surveyName);
signatureBundle.putString("quesname",selectedQues);
CaptureSignature signatureFrag=new CaptureSignature();
signatureFrag.setArguments( signatureBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout,signatureFrag, "signature");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("information"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle informationBundle=new Bundle();
informationBundle.putInt("questionnum",question_no);
informationBundle.putString("username",username);
informationBundle.putString("surveyname",surveyName);
informationBundle.putString("quesname",selectedQues);
InformationFragment informationFrag=new InformationFragment();
informationFrag.setArguments(informationBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout,informationFrag, "information");
transaction.commit();
}
else if(tablename.equals("signleselect"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle signleSelectBundle=new Bundle();
signleSelectBundle.putInt("questionnum",question_no);
signleSelectBundle.putString("username",username);
signleSelectBundle.putString("surveyname",surveyName);
signleSelectBundle.putString("quesname",selectedQues);
Single_Select singleSelectFrag=new Single_Select();
singleSelectFrag.setArguments(signleSelectBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.add(R.id.MyFrameLayout, singleSelectFrag, "singleselect");
transaction.commit();
}
c.close();
}
@SuppressLint("NewApi")
@Override
public void onClick(View v)
{
if(v.getId()==R.id.next)
{
i++;
Toast.makeText(this,tablename+i,Toast.LENGTH_LONG).show();
cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
if(cursor.moveToPosition(i))
{
tablename=cursor.getString(0);
Log.e("inside click",tablename);
}
Cursor c=db.getQuestionnum(username,surveyName,selectedQues);
if(valueQues!=0)
{
db.insertQuestion(valueQues);
Log.e("lastquestion_no"," "+question_no);
}
valueQues=0;
j++;
if(tablename.equals("numerictext"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle numericBundle=new Bundle();
numericBundle.putString("username",username);
numericBundle.putString("surveyname",surveyName);
numericBundle.putString("quesname",selectedQues);
numericBundle.putInt("questionnum",question_no);
NumericFragment numericFrag=new NumericFragment();
numericFrag.setArguments( numericBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
transaction.commit();
}
else if(tablename.equals("signature"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle signatureBundle=new Bundle();
signatureBundle.putInt("questionnum",question_no);
signatureBundle.putString("username",username);
signatureBundle.putString("surveyname",surveyName);
signatureBundle.putString("quesname",selectedQues);
CaptureSignature signatureFrag=new CaptureSignature();
signatureFrag.setArguments( signatureBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
transaction.commit();
}
else if(tablename.equals("information"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
Log.e("index",""+index);
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Log.e("value info","after"+i_information);
Bundle informationBundle=new Bundle();
informationBundle.putInt("questionnum",question_no);
informationBundle.putString("username",username);
informationBundle.putString("surveyname",surveyName);
informationBundle.putString("quesname",selectedQues);
//intent.putExtra("android.intent.extra.INTENT",numericBundle);
InformationFragment informationFrag=new InformationFragment();
informationFrag.setArguments(informationBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
transaction.commit();
}
else if(tablename.equals("email"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Log.e("value email","after"+i_email);
Bundle emailBundle=new Bundle();
emailBundle.putInt("questionnum",question_no);
emailBundle.putString("username",username);
emailBundle.putString("surveyname",surveyName);
emailBundle.putString("quesname",selectedQues);
EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
emailFrag.setArguments(emailBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
transaction.commit();
}
else if(tablename.equals("signleselect"))
{
selectedTableName=tablename;
if(c.moveToPosition(j))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle signleSelectBundle=new Bundle();
signleSelectBundle.putInt("questionnum",question_no);
signleSelectBundle.putString("username",username);
signleSelectBundle.putString("surveyname",surveyName);
signleSelectBundle.putString("quesname",selectedQues);
Single_Select singleSelectFrag=new Single_Select();
singleSelectFrag.setArguments(signleSelectBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout, singleSelectFrag, "singleselect");
transaction.commit();
}
c.close();
cursor.close();
}
else
{
i--;
cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
if(cursor.moveToPosition(i))
{
tablename=cursor.getString(0);
}
db.deletequestion(question_no);
Cursor c=db.getQuestion();
int pos=c.getCount();
pos--;
j--;
if(tablename.equals("numerictext"))
{
selectedTableName=tablename;
if(c.moveToPosition(pos))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.deletequestion(question_no);
}
Bundle numericBundle=new Bundle();
numericBundle.putString("username",username);
numericBundle.putString("surveyname",surveyName);
numericBundle.putString("quesname",selectedQues);
numericBundle.putInt("questionnum",question_no);
NumericFragment numericFrag=new NumericFragment();
numericFrag.setArguments( numericBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
transaction.commit();
}
else if(tablename.equals("signature"))
{
selectedTableName=tablename;
if(c.moveToPosition(pos))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.deletequestion(question_no);
}
Bundle signatureBundle=new Bundle();
signatureBundle.putInt("questionnum",question_no);
signatureBundle.putString("username",username);
signatureBundle.putString("surveyname",surveyName);
signatureBundle.putString("quesname",selectedQues);
CaptureSignature signatureFrag=new CaptureSignature();
signatureFrag.setArguments( signatureBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
transaction.commit();
}
else if(tablename.equals("information"))
{
selectedTableName=tablename;
if(c.moveToPosition(pos))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.deletequestion(question_no);
}
Bundle informationBundle=new Bundle();
informationBundle.putInt("questionnum",question_no);
informationBundle.putString("username",username);
informationBundle.putString("surveyname",surveyName);
informationBundle.putString("quesname",selectedQues);
InformationFragment informationFrag=new InformationFragment();
informationFrag.setArguments(informationBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
//transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}
else if(tablename.equals("email"))
{
selectedTableName=tablename;
if(c.moveToPosition(pos))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.deletequestion(question_no);
}
Bundle emailBundle=new Bundle();
emailBundle.putInt("questionnum",question_no);
emailBundle.putString("username",username);
emailBundle.putString("surveyname",surveyName);
emailBundle.putString("quesname",selectedQues);
EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
emailFrag.setArguments(emailBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
transaction.commit();
}
else if(tablename.equals("signleselect"))
{
selectedTableName=tablename;
if(c.moveToPosition(pos))
{
int index=c.getColumnIndex("question_no");
question_no= c.getInt(index);
db.insertQuestion(question_no);
}
Bundle signleSelectBundle=new Bundle();
signleSelectBundle.putInt("questionnum",question_no);
signleSelectBundle.putString("username",username);
signleSelectBundle.putString("surveyname",surveyName);
signleSelectBundle.putString("quesname",selectedQues);
Single_Select singleSelectFrag=new Single_Select();
singleSelectFrag.setArguments(signleSelectBundle);
FragmentManager manager=getFragmentManager();//create an instance of fragment manager
transaction=manager.beginTransaction();
transaction.replace(R.id.MyFrameLayout, singleSelectFrag, "singleselect");
transaction.commit();
}
c.close();
valueQues=question_no;
}
}
与
下一封电子邮件
、回一封电子邮件
、我的电子邮件
和反电子邮件
有很多混淆。请在打印的allLog.e
中发布更多的代码和logcat,为什么back\u email=-1
,这有什么意义吗?@ManishDubey:忽略这些,因为它们没有被使用,dsnt对我的代码有任何影响。而且我没有收到任何错误,因此日志catit无法帮助您检查基本活动中的ur,如果返回调用,请再次按下或第一个片段,或者如果您在其他活动中,它将清除所有backbackback条目,或者如果您站在主活动之一上,它会要求你再次按下返回,如果你再次按下,它会通过清除所有来返回。但它不会解决我的问题…我的问题是,例如,在电子邮件片段上,它显示来自数据库的问题第一个问题,其curosr值为0,因此使i_电子邮件的值为1,即使我再次按下下一步,下一个问题是信息片段它显示光标的第一个问题0 n将i_信息增加到1 n即使我按后退i_电子邮件也会减少,显示上一个问题,但即使我再次按下一步,这是信息片段i_信息的值仍然为1,但我需要光标0处的值。这是一个错误。这不是后退的问题。你每次都要关闭数据库,完成任务后。如果您需要显示数据库中的一些值,您需要编写两个查询。一个是从数据库获取所有信息,另一个是您的解决方案。它必须从数据库顶部为您提供一条记录。@ragiM.tech:这不是一个错误,但是的,您的第二个答案给了我一个提示。现在我想我可以解决我的问题了。谢谢,如果一切顺利,我会发帖的。。。