Solution 1 :
getInputType()
is not a value from EditText, it’s a type of EditText, e.g. textPersonName, textPersonName
, etc.
if you want value, you need to use getText()
String value= enterage.getText().toString();
int intValue = Integer.parseInt(value);
Problem :
[It should be that when I type 13-17, it goes to intent2 and when I type 18 or higher, it goes to intent3, but this is not the case.
public class nextscreen extends AppCompatActivity {
MediaPlayer mediaPlayer;
public Button btn;
public EditText enterage;
@Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nextscreen);
mediaPlayer = MediaPlayer.create(nextscreen.this, R.raw.background_music);
mediaPlayer.setLooping(true);
mediaPlayer.start();
btn = (Button) findViewById(R.id.agebutton);
enterage = (EditText) findViewById(R.id.enterage);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int inputage = enterage.getInputType();
if (inputage <= 12) {
Intent int1 = new Intent(nextscreen.this, nextscreen1.class);
startActivity(int1);
}
else if (inputage <= 17){
Intent int2 = new Intent(nextscreen.this, nextscreen2.class);
startActivity(int2);
}
else {
Intent int3 = new Intent(nextscreen.this, nextscreen3.class);
startActivity(int3);
}
]1
Comments
Comment posted by Community
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it’s currently written, it’s hard to tell exactly what you’re asking.