Skip to content Skip to sidebar Skip to footer

About Android Button Event

Hi I am new in android application development.I am practicing the android development for a while.Here is what i am trying to do: In the screen there is two spinner named 'To' a

Solution 1:

This is just the crude code, I haven't tested, I just wrote on top of my head, so there can be some errors and I just assumed some layout ids. You need to figure that out.

public class SpinnerExample extends Activity {
private String array_spinner[];
private Spinner toSpinner;
private Spinner fromSpinner;
private Button btnClear;
private EditText etAmount;
private EditText etResult;
@Override
public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     array_spinner=new String[3];
     array_spinner[0]="1";
     array_spinner[1]="2";
     array_spinner[2]="3";

fromSpinner = (Spinner)findViewById(R.id.fSpinner);
toSpinner = (Spinner)findViewById(R.id.tSpinner);
ArrayAdapter fromadapter = new ArrayAdapter(this,
android.R.layout.fspinneritem, array_spinner);
ArrayAdapter toadapter = new ArrayAdapter(this,android.R.layout.tspinner_item,array_spinner);

btnClear = (Button)findViewById(R.id.clear_button);


btnClear.setOnClickListener(new Button.OnClickListener(){
     public void onClick(View v){
       etAmount = (EditText)findViewById(R.id.amount_et);
       etResult = (EditText)findViewById(R.id.result_et);
       etAmount.setText("");
       etResult.setText("");
       fromSpinner.setAdapter(fromadapter);
       toSpinner.setAdapter(toadapter);
    }
});

}
}

Post a Comment for "About Android Button Event"