当我单击并选择Spinner项时,光标将自动进入空白编辑文本?

时间:2014-07-01 05:42:25

标签: java android xml android-edittext spinner

例如:包含Cash,Check.i等3个项目的Spinner也声明了3个编辑文本,如checkno,chekdd,支付金额。当我点击现金项目时,它将自动链接到金额付费的edittext。

Spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> arg0,
            View arg1, int arg2, long arg3) {

        if(spinnerText2.equalsIgnoreCase("CASH"))
        {
            amountedittxt.setText(spinnerText2);
            amountedittxt.setVisibility(View.GONE);
        }
    }
});

2 个答案:

答案 0 :(得分:2)

要将焦点设置在您的edittext上,您可以在其上调用requestFocus

if(spinnerText2.equalsIgnoreCase("CASH"))
{
    amountedittxt.setVisibility(View.VISIBLE);
    amountedittxt.requestFocus();
    amountedittxt.setText(spinnerText2);
}

确保您已在xml中添加android:focusable="true" for edittext,如下所示:

<EditText
    android:id="@+id/amount"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"/>

答案 1 :(得分:1)

也尝试这个

String amountedittxt = textExm.getText()。toString();

               textExm.setFocusable(true);
                textExm.setFocusableInTouchMode(true);
                textExm.setFocusable(true);