2012-03-31 1 views
0

私は2つのボタンを持つRadioGroupを持っています。選択されているラジオボタンに応じて特定のアクティビティを開きますか?

「作成」ボタンを押すと、の2つのアクティビティのうちの1つがに開始されます。最初のラジオボタンが「作成」ボタンが押されたときにチェックされている場合は、「ProductSearch」アクティビティが開きます。

「作成」ボタンが押されたときに第2のラジオボタンタイプがチェックされている場合、「タイプエントリー」アクティビティが開きます。しかし、今は、どのRadioButtonが押されても、 "ProductSearch"が開きます。

検索では、タイプではありません。です。

RadioButton search = (RadioButton) findViewById(R.id.radio1); 
    RadioButton type = (RadioButton) findViewById(R.id.radio2); 

    Button create = (Button) findViewById(R.id.create); 
    if(search.isChecked()){ 
     create.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent createIntent = new Intent(getApplicationContext(), ProductSearch.class); // <----- START "SEARCH" ACTIVITY 
      startActivityForResult(createIntent, 0); 
     } 
    }); 
    }else if(type.isChecked()){ 
     create.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent typeIntent = new Intent(getApplicationContext(), TypeEntries.class); // <----- START "TYPE ENTRIES OUT" ACTIVITY 
      startActivityForResult(typeIntent, 0); 

     } 
     }); 
    }  
    } 
} 

答えて

2

これを試してみてください。

RadioButton search = (RadioButton) findViewById(R.id.radio1); 
    RadioButton type = (RadioButton) findViewById(R.id.radio2); 

    Button create = (Button) findViewById(R.id.create); 
    create.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
     if(search.isChecked()){ 
      Intent createIntent = new Intent(getApplicationContext(), ProductSearch.class); // <----- START "SEARCH" ACTIVITY 
      startActivityForResult(createIntent, 0); 
      } 
      else 
      { 
       if(type.isChecked()) 
       { 
       Intent typeIntent = new Intent(getApplicationContext(), TypeEntries.class); // <----- START "TYPE ENTRIES OUT" ACTIVITY 
       startActivityForResult(typeIntent, 0); 
       } 
      } 
     } 
    }); 
+0

は...私の答えのように働いた:) – Mayank

+0

おかげで、見えます! – Cole

関連する問題