关于 Android 按钮事件 [英] About Android button event
问题描述
嗨我是 android 应用程序开发的新手.我正在练习 android 开发一段时间.这是我想要做的:
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:
在屏幕上有两个名为To"和From"的微调器和两个名为Amount"和Result"的编辑文本按钮.我想执行以下操作:
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:
当点击清除按钮时,它会将To"和From"重置为默认值并清除Amount"和Result".
when Clear button clicked it 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.
推荐答案
这只是粗略的代码,我没有测试过,我只是写在我的头上,所以可能会有一些错误,我只是假设了一些布局 ID.你需要弄清楚这一点.
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);
}
});
}
}
这篇关于关于 Android 按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!