Класс строительства
protected Spinner tipSpinner;
private ArrayAdapter<CharSequence> adapterTip;
Внутри onCreate после setContentView (R.layout.main);
Spinner spinner= (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapterTip = ArrayAdapter.createFromResource(this, R.array.tipArray, android.R.layout.simple_spinner_item);
adapterTip.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapterTip);
spinner.setSelection(14, true);
spinner.setOnItemSelectedListener(new tipSelectorListener());
Spinner Listener
public class tipSelectorListener implements OnItemSelectedListener{
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id) {
Toast.makeText(parent.getContext(), "TEST " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent){
//Do Nothing
}
}
Ввод EditText - Расчет вызова при смене ключа, изменение значения счетчика
billAmount = (EditText)findViewById(R.id.textLblBillAmount);
EditText billAmount = (EditText) findViewById(R.id.textLblBillAmount);
billAmount.setOnKeyListener(new EditText.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
recalculate();
//Spinner tipSpinner.setSelection(0, true);
Toast toast = Toast.makeText(getBaseContext(), "TEST", Toast.LENGTH_SHORT);
toast.show();
return true;
}
return false;
}
});
Метод расчета
public void recalculate(){
// Recalculate Values of all
tipSpinner.setSelection(0, true);
}
Ошибка нулевого указателя при изменении EditText, думаю, что это c