how to place different conditions of performance onClick in radibuttons
-
There's a display:
And code:
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ ImageView plus; ImageView minus; TextView tvResult; TextView cena; TextView cena_53_skritaya; TextView cena_73_skritaya; RadioGroup radioGroup_cena;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); plus = (ImageView) findViewById(R.id.plus); plus.setOnClickListener(this); minus= (ImageView) findViewById(R.id.minus); minus.setOnClickListener(this); tvResult = (TextView) findViewById(R.id.tvResult); cena = (TextView) findViewById(R.id.cena); cena_53_skritaya = (TextView) findViewById(R.id.textView_53); cena_73_skritaya = (TextView) findViewById(R.id.textView_73); radioGroup_cena = (RadioGroup) findViewById(R.id.radioGroup_cena); radioGroup_cena.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.radioButton_250: cena.setText("53"); break; case R.id.radioButton_500: cena.setText("73"); break; } } }); } @Override public void onClick(View v) { int parse_kolichestvo; int parse_cena_53; int num2 = 1; int result = 0; int resultcena=0; // читаем TextView и заполняем переменные числами parse_kolichestvo = Integer.parseInt(tvResult.getText().toString()); parse_cena_53 = Integer.parseInt(cena_53_skritaya.getText().toString()); switch (v.getId()) { case R.id.plus: result = parse_kolichestvo + num2; resultcena= result*parse_cena_53; } switch (v.getId()) { case R.id.minus: result = parse_kolichestvo - num2; if (parse_kolichestvo==1){ return; } resultcena= result*parse_cena_53; } // формируем строку вывода tvResult.setText( String.valueOf(result) ); cena.setText( String.valueOf(resultcena) ); }
}
As you can see in OnClick, the program passes the first number (53) and multiplies the number, in this case, 1 plus and minus (Image View) changes the quantity and takes a step. Now, the question of how to move this cycle to the
switch (checkedId) {
case R.id.radioButton_250:
cena.setText("53");
break;
And then you'll have another cycle of work,
case R.id.radioButton_500:
cena.setText("73");
break;
But it's 73, not 53.
I tried myself, but there are problems with the ImageView symbol for each of the cycles.
-
It's kind of like... I haven't seen a single cycle in the code that you want to move... But looking at your scroll case, the design of the building.
onClick
I understand that you don't know what you're doing. But we were all once like this, so I'll try.In fact, from what I tried to figure out from your rebus, I'm not sure you're doing the right thing.
onClick
Method of using field data that are filled by cell selection toolsCheckGroup
Not fromInteger.parseInt(cena_53_skritaya.getText().toString())
♪ Then you won't care what element is chosen and the logic will work exactly for the price you've set in.CheckGroup
♪