0
你好我实现一个计算器式键盘我的应用程序在键盘上用户点击它希望在EDITTEXT显示,但我没有得到任何错误,也没有结果这里是我的Java代码Android计算器键盘按钮OnClickListener无法正常工作?
这里是我KeypadAdapter.java
public class KeypadAdapter extends BaseAdapter {
private Context mContext;
public KeypadAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mButtons.length;
}
public Object getItem(int position) {
return mButtons[position];
}
public long getItemId(int position) {
return 0;
}
// create a new ButtonView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
Button btn;
if (convertView == null) { // if it's not recycled, initialize some attributes
btn = new Button(mContext);
KeypadButton keypadButton = mButtons[position];
// Set CalculatorButton enumeration as tag of the button so that we
// will use this information from our main view to identify what to do
btn.setTag(keypadButton);
}
else {
btn = (Button) convertView;
}
btn.setText(mButtons[position].getText());
return btn;
}
// Create and populate keypad buttons array with CalculatorButton values
private KeypadButton[] mButtons = {KeypadButton.SEVEN,KeypadButton.EIGHT, KeypadButton.NINE,
KeypadButton.FOUR, KeypadButton.FIVE,KeypadButton.SIX,
KeypadButton.ONE, KeypadButton.TWO, KeypadButton.THREE,
KeypadButton.ZERO,KeypadButton.DOT,KeypadButton.BACKSPACE };
public void setOnButtonClickListener(OnClickListener onClickListener) {
// TODO Auto-generated method stub
}
public enum KeypadButton {
BACKSPACE("Clear",KeypadButtonCategory.CLEAR)
, ZERO("0",KeypadButtonCategory.NUMBER)
, ONE("1",KeypadButtonCategory.NUMBER)
, TWO("2",KeypadButtonCategory.NUMBER)
, THREE("3",KeypadButtonCategory.NUMBER)
, FOUR("4",KeypadButtonCategory.NUMBER)
, FIVE("5",KeypadButtonCategory.NUMBER)
, SIX("6",KeypadButtonCategory.NUMBER)
, SEVEN("7",KeypadButtonCategory.NUMBER)
, EIGHT("8",KeypadButtonCategory.NUMBER)
, NINE("9",KeypadButtonCategory.NUMBER)
, DOT(".",KeypadButtonCategory.OTHER);
CharSequence mText; // Display Text
KeypadButtonCategory mCategory;
KeypadButton(CharSequence text,KeypadButtonCategory category) {
mText = text;
mCategory = category;
}
public CharSequence getText() {
return mText;
}
}
public enum KeypadButtonCategory {
MEMORYBUFFER
, NUMBER
, OPERATOR
, DUMMY
, CLEAR
, RESULT
, OTHER
}
}
所以请帮我解决这个问题..........
您好@chefburns你能详细解答与代码.... thanq – androidgeek 2013-03-08 10:07:44
好吧,所以我想要实现,而不是...... – androidgeek 2013-03-08 10:25:42
如果你把你的OnClickListener的代码,并把它放在你的OnItemClickListener那么它应该工作,你可以删除mKeyAdapter.setOnButtonClickAdapter,因为它没有被使用。 – chefburns 2013-03-08 10:31:51