1 Replies - 8992 Views - Last Post: 13 November 2010 - 10:39 PM

#1 irmoathlete  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 98
  • Joined: 09-July 10

android app, EditText parsing to int?

Posted 12 November 2010 - 09:02 PM

is there any way to .getText() from the EditText and then parse it to an int. The only way I have come up with to do this is to do something like
Integer.parseInt((String)something.getText())



heres what my code looks like so far. I'm dealing with numbers so I would really need to figure out a way to be able to get integers and doubles from the EditTexts.


package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class HelloAndroid extends Activity 
{
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);         
		Button calculateButton = (Button) findViewById(R.id.calculateButton);

		final TextView incomeEntry = (TextView) findViewById(R.id.incomeEntry);
		final TextView mortgageEntry = (TextView) findViewById(R.id.mortgageEntry);


		calculateButton.setonclickListener(new View.onclickListener() 
		{
			public void onclick(View v) 
			{         
				setContentView(R.layout.calc);
				TextView incomeCalc = (TextView) findViewById(R.id.incomeCalc);
				incomeCalc.setText(""+incomeEntry.getText());
				TextView mortgageCalc = (TextView) findViewById(R.id.mortgageCalc);
				//double mortgageInt = Double.parseDouble((String) mortgageEntry.getText());
				mortgageCalc.setText("Mortgage: $"+mortgageEntry.getText()+"     % of income: %");
			}
		});
	}
}





Is This A Good Question/Topic? 0
  • +

Replies To: android app, EditText parsing to int?

#2 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 276
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: android app, EditText parsing to int?

Posted 13 November 2010 - 10:39 PM

something.getText().toString()

This will give your the String.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1