我正在编写一个应用程序,它本质上是一张可以翻转的卡片。双方都有某些相关数据,一边说是提示,另一边是图片。数据的双方都是相关的。我的问题是我可以通过单击下一步来浏览卡片但是当我翻转卡片进行图片时,由于重新加载了第一个活动,我又回到了开头。我该如何解决这个问题?我的代码是:包 org.v2.greTouch;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
public class FlipCard extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
Cursor cur;
TextView tv;
DbH db;
ImageButton next,back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.TV_Word);
next=(ImageButton)findViewById(R.id.next);
back=(ImageButton)findViewById(R.id.back);
next.setOnClickListener(this);
back.setOnClickListener(this);
LinearLayout turn;
turn=(LinearLayout)findViewById(R.id.LL_Card);
turn.setOnClickListener(this);
try {
db=new DbH(this);
} catch (IOException e2) {
e2.printStackTrace();
}
try {
db.createdatabase();
} catch (IOException e) {
e.printStackTrace();
}
db.opendatabase();
cur=db.data();
cur.moveToFirst();
tv.setText(cur.getString(0));
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.next :
if(cur.isLast())
{
cur.moveToFirst();
tv.setText(""+cur.getString(0));
}
else
{
cur.moveToNext();
tv.setText(""+cur.getString(0));
}
break;
case R.id.back:
{
if(cur.isFirst())
{
cur.moveToLast();
tv.setText(""+cur.getString(0));
}
else {cur.moveToPrevious();
tv.setText(""+cur.getString(0));
}
break;
}
case R.id.LL_Card:
{
Intent i=new Intent(this,FlashCard_back.class);
startActivity(i);
}
}
}
}
加载的另一面是:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
public class FlashCard_back extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_back);
LinearLayout layMain = (LinearLayout) findViewById(R.id.FlashCardRear);
layMain.setOnClickListener(this);
}
public void onClick(View v) {
Intent i=new Intent(this,FlipCard.class);
startActivity(i);
}
}
我希望当我退回时,我应该得到同一张卡片,其中包含从数据库中提取的值。请帮忙。