java
html
c
xml
python
linux
android
ruby-on-rails
regex
objective-c
visual-studio
eclipse
algorithm
facebook
cocoa
apache
mvc
asp
postgresql
dom
The problem is when the app loads up onCreate() is called and there is nothing in the textbox so when you call val3.getText().toString() there is nothing there. I would suggest
val3.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) { val2 = val3.getText().toString() } public void beforeTextChanged(CharSequence s, int start, int count, int after){} public void onTextChanged(CharSequence s, int start, int before, int count){} });
so when you enter the value it will grab it after you are done entering it.
Looks like your performing your conversion immediately on activity creation instead of when someone hits the convert button. You have an onClick listener defined in your layout but you're not using it... try adding this function:
onClick
public void converter(View view) { EditText val3 = (EditText)findViewById(R.id.BeforeBox); String val2 = val3.getText().toString(); if(val2.length() > 0) { val1 = Integer.parseInt(val2); forResult = changeFormat(converter(val1)); TextView AfterBox = (TextView)findViewById(R.id.AfterBox); AfterBox.setText(forResult); } }
and change your onCreate() to this:
onCreate()
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner spinner1 = (Spinner) findViewById(R.id.Spinner1); ArrayAdapter adapter1 = ArrayAdapter.createFromResource( this, R.array.UnitList, android.R.layout.simple_spinner_item); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(adapter1); }