A
A
Alexey R2014-05-28 20:01:10
Android
Alexey R, 2014-05-28 20:01:10

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

1 answer(s)
S
svd71, 2014-05-28
@Axeles

edittext.setText(""+num1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question