0

我知道这是一个有点愚蠢和奇怪的问题,但它真的困扰着我。正如我的帖子主题所说,当我在编辑文本中输入一个字母时,它会打印两次。我试图找出问题所在,但找不到。这是我的代码,

更改代码.xml

<EditText
    android:id="@+id/oldcode"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/changecodetxt"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="20dp"
    android:hint="Enter Old Pass Code"
    android:inputType="number"
    android:password="true" />

<EditText
    android:id="@+id/newcode"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/oldcode"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="20dp"
    android:hint="Enter New Pass code"
    android:inputType="number"
    android:password="true" />

<EditText
    android:id="@+id/renewcode"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/newcode"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="25dp"
    android:hint="Re-Enter New Pass code"
    android:inputType="number"
    android:password="true" />

<Button
    android:id="@+id/savenewcode"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/button_style"
    android:text="Update Code" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/savenewcode"
    android:layout_below="@id/renewcode"
    android:gravity="center" >

    <ToggleButton
        android:id="@+id/cc_togglebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:textOff="123"
        android:textOn="ABC!@#" />
</LinearLayout>

MainActivity.java

oldcode = (EditText) findViewById(R.id.oldcode);
                newcode = (EditText) findViewById(R.id.newcode);
                renewcode = (EditText) findViewById(R.id.renewcode);
                savenewcode = (Button) findViewById(R.id.savenewcode);
                cc_toggle = (ToggleButton) findViewById(R.id.cc_togglebutton);

                cc_toggle.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        boolean on = cc_toggle.isChecked();
                        if (on) {

                            oldcode.setInputType(InputType.TYPE_CLASS_TEXT);
                            newcode.setInputType(InputType.TYPE_CLASS_TEXT);
                            renewcode.setInputType(InputType.TYPE_CLASS_TEXT);
                        }

                        else {

                            oldcode.setInputType(InputType.TYPE_CLASS_NUMBER);
                            newcode.setInputType(InputType.TYPE_CLASS_NUMBER);
                            renewcode.setInputType(InputType.TYPE_CLASS_NUMBER);
                        }                           
                    }
                });

非常感谢任何形式的帮助或建议。

4

0 回答 0