1
对于初学者,任何帮助将不胜感激!我创建了一个数字小键盘,每次选择其中一个按钮时,都需要将数值传递给EditText。我遇到了一个问题,即EditText被setText覆盖,每次按下不同的按钮。我真的需要连接每个值,我不太确定如何做到这一点。任何一个到九个按钮都可以按任意顺序按下。Android用户输入,使用自定义键盘
这是一些代码。我只是想让这些键首先工作。
View hash = findViewById(R.id.keypad_hash);
hash.setOnClickListener(this);
View key1 = findViewById(R.id.keypad_1);
key1.setOnClickListener(this);
View key2 = findViewById(R.id.keypad_2);
key2.setOnClickListener(this);
}
@Override
public void onClick(View v){
switch(v.getId()){
case R.id.keypad_hash:
questions();
break;
case R.id.keypad_1:
final EditText number_edit_text1 = (EditText) this.findViewById(R.id.Edit);
number_edit_text1.setText(String.valueOf("1"));
break;
case R.id.keypad_2:
final EditText number_edit_text2 = (EditText) this.findViewById(R.id.Edit);
number_edit_text2.setText(String.valueOf("2"));
break;
}
}
,然后在布局中的EditText
<EditText
android:id="@+id/Edit"
android:layout_height="wrap_content"
android:inputType="number"
android:layout_width="fill_parent"
android:numeric="integer">
</EditText>
嘿,男士,感谢您的快速反应。我实施了你的建议,我已经有了它的工作。非常感谢您的详细解答。不够感谢你。 – Abs90 2012-02-22 01:23:33
不客气。 :) – Jakar 2012-02-22 01:30:09