0

[ここ][1] などのボタンを使用してユーザーから入力を取得するためのオンライン チュートリアルをいくつかチェックしていましたが、それは私が求めていたものではなく、同様の問題に遭遇した人がいるかどうかを知りたいと考えていました。

ボタンがクリックされたときにinteger input のみ入力するようにユーザーに促したいのですがTextField、ユーザーがボタンをクリックするまで画面に表示したくありません。ユーザー入力は に保存する必要がありint biasます。

どんな助けでも大歓迎です。

4

7 に答える 7

1

キーボードの数字で表示するには、この行android:inputType="number"を EditText に追加します

 <EditText android:id="@+id/edittext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="number"
   />

edittext をダイアログに表示する場合は、customdialog Dialogs Exampleを使用mDialog.show()し、ボタン クリック リスナーで使用します。

ここmDialogにオブジェクトがありますDialog

于 2013-09-02T04:32:14.463 に答える
1

textFieldあなたが話していることが何であれ、入力タイプを次のように設定できます。

textFieldName.setRawInputType(Configuration.KEYBOARD_12KEY);

次のように XML で直接設定できます。

android:inputType="number"

また、TextField を作成する場合でも、次を使用して可視性を Invisible に設定できます。

textFieldName.setVisibility(View.INVISIBLE);

次に、ユーザーがボタンをクリックすると、次を使用して Visible に設定できます。

textFieldName.setVisibility(View.VISIBLE);

質問で述べたように、ボタンクリックの可視性を変更できます。

于 2013-09-02T04:31:07.827 に答える
1

このテキストフィールドをレイアウトに追加して、その可視性を設定できます"gone"

boolean isClicked  =  false;
String userInput = null;

Button grayScaleFilterButton = (Button) findViewById(R.id.filter1_button);
    grayScaleFilterButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        if(isClicked){
         isClicked = false;
              //Got the input and hide the textfield.
             userInput  = textField.getText().toString();
             textField.setVisibility(View.GONE);

        }else{
              //make the textfield visible and user can enter the input.
          isClicked = true;
              textField.setInputType(InputType.TYPE_CLASS_NUMBER);
          textField.setVisibility(View.VISIBLE);
        //do something

        }


        }
    });
于 2013-09-02T04:40:14.577 に答える
1

XML コード

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:padding="5dp"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/edtInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:visibility="gone" />

        <Button 
            android:id="@+id/btnInput"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="Input"/>
    </LinearLayout>

</LinearLayout>

活動コード

public class MyInputActivity extends Activity implements OnClickListener {

    private EditText edtInput;
    private Button btnInput;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my);

        edtInput = (EditText) findViewById(R.id.edtInput);
        btnInput = (Button) findViewById(R.id.btnInput);

        btnInput.setOnClickListener(this);
    }

    @Override
    public void onClick(View arg0) {
        if(edtInput.getVisibility() == View.VISIBLE){
            edtInput.setVisibility(View.GONE);
            // write your more code here on gone
        }else{
            edtInput.setVisibility(View.VISIBLE);
            // write your more code here on visible
        }
    }
}
于 2013-09-02T04:55:44.823 に答える
0

xml のこの行で入力タイプ番号を設定できます。このコードを使用すると、ユーザーはソフトウェア キーボードからのみ 0、1、..9 の数字をクリックできます。

       android:digits="1234567890" or  android:inputType="number"
于 2013-09-02T04:53:07.783 に答える