Answer the question
In order to leave comments, you need to log in
How to parse number from EditText in Android?
Good day, please forgive me, could you tell me where I can read about parsing and what it is. The matter is that I need to receive number from TextView or Edit Text but I cannot make it. When the button is clicked, an error occurs. To analyze the situation, I created a simple project. In which there is a button, it edits the text and the text of the view. It is necessary from edit tex when you click on the button to get a number that will be entered in the text of the view. But all the time I run into an error. Tell me which direction to go.
Button button1;
EditText edittext;
TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
edittext = (EditText) findViewById(R.id.editText1);
textview = (TextView) findViewById(R.id.textView1);
button1.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
int num1 = Integer.parseInt(edittext.getText().toString());
edittext.setText(num1);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question