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