0

こんにちは私はここで1つのアプリを実行しています。ユーザークリックボタンは、別のアクティビティで1つのアクションを実行する必要があることを意味し、ユーザーは再び同じページに戻ります。同じボタンをクリックすると、別のアクションを実行する必要があります。私はactivity1で2つのアクティビティを取得します。1つのボタンがあります。activity1ボタンで1つのカウント変数を使用してtreidします。そのときにカウント変数をインクリメントし、putextraを使用して、アクションを実行するカウントに基づいて、ここでそのカウント値をacticity2に取得します。増加して、同じactivty1に戻った場合、カウントも「1」のみであるボタンをクリックします。2に増加しません。したがって、その問題を解決する方法は、アイデアを持っている人なら誰でも私に提案します。

 Activity1 .class:
 public class Activity1 extends Activity implements OnClickListener{
Button b1,b2;
  int countk4=0;

   SharedPreferences share;
   String bol3;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.home1);
     b1=(Button)findViewById(R.id.button1);
    b1.setOnClickListener(this);
   }

public void onClick(View v) {
    // TODO Auto-generated method stub
    if(v==b1)
    {
        countk4++;
         share=getSharedPreferences("shared", MODE_WORLD_WRITEABLE);
         SharedPreferences.Editor editor=share.edit();

         editor.putInt("roll", countk4);

         editor.commit();

         show();
        Intent i=new Intent(Activity1 .this,Activity2.class);
        i.putExtra("k", 1);
        i.putExtra("k1", 13);
        i.putExtra("ks", val1);
        startActivity(i);
    }
}
Integer val1,val2;
private void show() {
    // TODO Auto-generated method stub
    share=getSharedPreferences("shared", MODE_WORLD_READABLE);

     val1=share.getInt("roll",0);

    }
       }

  Activity2 .class:
   public class Activity2 extends Activity implements OnClickListener{
Button back;
      int countkv;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.home2);
     back=(Button)findViewById(R.id.button1);
    back.setOnClickListener(this);
          countkv = getIntent().getIntExtra("ks", 0); 

  if(countkv =1)
    {
   Toast.makeText(getApplicationContext(), "hai.......i am first", Toast.LENGTH_LONG).show(); 
   }

if(countkv =2)
{
   Toast.makeText(getApplicationContext(), "hai.......1 am second", Toast.LENGTH_LONG).show(); 
   }

  public void onClick(View v) {
    // TODO Auto-generated method stub
    if(v==back)
    {
        Intent i=new Intent(Activity2.this,Activity1.class);


        startActivity(i);
    }


}
}
}
 but above every time first toast message displayed becz countkv is every time 1 only..
4

1 に答える 1

0

受信側でのオブジェクトを作成しますBundle

    Bundle myBundle = new Bundle(); // Declare above
    String temp;

    myBundle = getIntent().getIntExtra();
    temp = myBundle.getString("ks"); // temp will have the val1.

あなたが今それを手に入れることができることを願っています。

于 2012-04-27T11:25:32.327 に答える