0

2つのボタンが含まれるRadioGroupがあります。

「作成」ボタンがあり、押すと2つのアクティビティのいずれかが開始されます。「作成」ボタンが押されたときに最初のラジオボタンである検索がチェックされている場合、「ProductSearch」アクティビティが開くはずです。

「作成」ボタンが押されたときに2番目のラジオボタンtypeがチェックされている場合、「TypeEntries」アクティビティが開くはずです。ただし、今のところ、どの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);

        }
      });
    }    
  } 
}
4

1 に答える 1

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);
              }
            }
        }
    });
于 2012-03-31T23:03:10.203 に答える