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" and "From" and two edit text button named "Amount" and "Result".i want to do the following:
when Clear button clicked i开发者_Go百科t will reset the “To” and “From” to a default values and clear “Amount” and “Result”.
Can anybody have any idea?it will be very helpful if i get the code. Thanks.
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);
}
});
}
}
精彩评论