关于Android的按钮事件 [英] About Android button event
问题描述
喜 我是新的Android应用程序development.I我练了while.Here 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:
在屏幕上有两个名为微调到和从和两个编辑文本按钮,命名为量和结果。我要做到以下几点:
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 it will reset the "To" and "From" to a default values and clear "Amount" and "Result".
任何人都可以有什么想法?这将是非常有益的,如果我得到的code。 谢谢你。
Can anybody have any idea?it will be very helpful if i get the code. Thanks.
推荐答案
这仅仅是原油code,我没有测试过,我只是写在我的头顶,所以可以有一些错误,我刚刚就任的一些布局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屋!