Some of my coding is as follows. The first button (button2) is for exit which is working fine on my emulator and phone but the (button 1) which is supposed to take input from a TextView and add 777 and then display as a toast message is not working in either of them.
public class TimerCodeActivity extends Activity {
protected TextView timebox;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timerlayout);
timebox = (TextView) findViewById(R.id.timebox);
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
finish();
System.exit(0);}
});
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
String timeboxRepresentation = (String) timebox.getText();
int Digit = Integer.parseInt(timeboxRepresentation.substring(0,2));
int total = Digit + 777;
Toast.makeText(TimerCodeActivity.this, String.valueOf(total), Toast.LENGTH_LONG).show();
}
});
}}
Thank you in advance for any assistance.
try this:
and just remove
it’s useless.