【问题标题】:how to create and implementing numeric key pad in android如何在android中创建和实现数字小键盘
【发布时间】:2014-04-22 08:20:08
【问题描述】:

我创建了一个生成按钮运行时的类,我想将该类实现为特定编辑文本字段中的键盘,我该怎么做。我的班级代码如下

public class KeyboardView extends View
{

    LinearLayout verticalLinearLayout, horizontalLinearLayout;
    Button button, btnZero, btnPoint, btnDone;




    public KeyboardView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public KeyboardView(Context context,AttributeSet attributeSet) {
        super(context, attributeSet);
        // TODO Auto-generated constructor stub
    }

    public KeyboardView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        // TODO Auto-generated constructor stub
    }

    public LinearLayout addView(){
        verticalLinearLayout = new LinearLayout(getContext());
        verticalLinearLayout.setOrientation(LinearLayout.VERTICAL);
        int count = 1;
        for (int i = 1; i <= 3; i++) {
            horizontalLinearLayout = new LinearLayout(getContext());
            for (int j = 1; j <= 3; j++) {

                button = new Button(getContext());
                button.setText(String.valueOf(count++));
                button.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        ((Button)v).getText();
                    }
                });
                horizontalLinearLayout.addView(button);

            }
            verticalLinearLayout.addView(horizontalLinearLayout);
        }

        horizontalLinearLayout = new LinearLayout(getContext());

        btnZero = new Button(getContext());
        btnZero.setText("0");
        horizontalLinearLayout.addView(btnZero);

        btnPoint = new Button(getContext());
        btnPoint.setText(".");
        horizontalLinearLayout.addView(btnPoint);

        btnDone = new Button(getContext());
        btnDone.setText("Done");
        horizontalLinearLayout.addView(btnDone);

        verticalLinearLayout.addView(horizontalLinearLayout);

        return verticalLinearLayout;

    }


    public Button getButton() {
        return button;
    }

    public Button getBtnZero() {
        return btnZero;
    }

    public Button getBtnPoint() {
        return btnPoint;
    }

    public Button getBtnDone() {
        return btnDone;
    }
}

我想在某些特定的编辑文本视图中将此类实现为键盘,请有人帮助我吗?

【问题讨论】:

    标签: android custom-controls android-keypad


    【解决方案1】:

    您可以点击 2 个链接。比如

    1#号:Creating a Numeric Keypad with GridLayout

    和2号#Introduction to Android development : TouchCalculator

    我希望您会从这些链接中获得帮助。祝你好运!

    【讨论】:

    • 但是我使用类文件作为视图,我希望真正的键盘出现在我们面前
    猜你喜欢
    • 1970-01-01
    • 2017-01-01
    • 2012-10-26
    • 2014-10-03
    • 2017-12-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多