I want to make an App with 2 Activitys, in the first Activity I need an EditText
and Button
and in the second Activity need to be TextView
.
The app will open in the First Activity. You need to write in the EditText
an int number, after you have chosen a number you need to click on the button and it will move you to the second Activity, if You have chosen a number in range 1 to 5, in the textView
it needs to to be Write "Low Number" if the number is in range 5 to 10 it needs to be Write "High Number".
Activity1:
public class Mul extends AppCompatActivity {
private final String NUMBER = "Number";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mul);
}
public void btnonly(View view) {
EditText etonly = (EditText) findViewById(R.id.etonly) ;
Intent intent = new Intent(Mul.this, MulOnly.class);
intent.putExtra("Number", etonly.getText().charAt(0));
startActivity(intent);
}
}
Activity2:
public class MulOnly extends AppCompatActivity {
int ab;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mul_only);
ab=getIntent().getIntExtra("Number",0);
TextView tv = (TextView) findViewById(R.id.textView);
if (ab > 0 && ab < 6)
{
tv.setText("Low Number");
}
if (ab > 5 && ab < 11)
tv.setText("High Number");
}
}
Why does it not work?
If I put in EditText number nvm what is the number it doesn't change the TextView in the next Activity