Android 将EditText的InputType设置为TYPE_NULL后,我无法更改它
我使用以下命令将EditText的InputType设置为TYPE_NULL:Android 将EditText的InputType设置为TYPE_NULL后,我无法更改它,android,null,android-edittext,input-type-file,Android,Null,Android Edittext,Input Type File,我使用以下命令将EditText的InputType设置为TYPE_NULL: editText.setInputType(InputType.TYPE_NULL); 我可以将其设置为类型_NULL,它可以工作!但是如果我想将InputType设置为其他类型,比如TYPE\u CLASS\u TEXT,它就不起作用了 如何在代码中动态更改它?要键入\u NULL,然后键入\u CLASS\u TEXT并再次键入\u NULL?要执行此操作,您首先必须更改输入类型,然后动态向其添加文本,如下所示
editText.setInputType(InputType.TYPE_NULL);
我可以将其设置为类型_NULL,它可以工作!但是如果我想将InputType设置为其他类型,比如TYPE\u CLASS\u TEXT,它就不起作用了
如何在代码中动态更改它?要键入\u NULL,然后键入\u CLASS\u TEXT并再次键入\u NULL?要执行此操作,您首先必须更改输入类型,然后动态向其添加文本,如下所示
editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setText("Hello");
我已经试过了。但它不起作用!我无法将其从空更改为文本!当我将inputtype从null更改为text后,当我单击edittext时,键盘不会弹出!然后使用InputType.TYPE\u CLASS\u TEXT\u VARIATION\u NORMALomg代替InputType.TYPE\u CLASS\u TEXT。InputType.TYPE\u文本\u变体\u正常始终更改编辑文本。。。总是在全屏编辑文本之前和输入TYPE.TYPE\u TEXT\u VARIATION\u NORMAL之后,它是默认的编辑文本。为什么?我有一个包含编辑文本列表的recycler视图。EditText的输入类型取决于EditText的功能。有些具有单击功能,可以从对话框中选择数据。所以他们输入了null。但在recycler视图中,如果EditText的InputType为空,则我无法将InputType更新为Text。由于循环使用,使用已创建的视图。
// Try this one
**activity_main1.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="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<EditText
android:id="@+id/txtValue"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btnClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Input" />
</LinearLayout>
public class MainActivity1 extends Activity {
private Button btnClick;
private TextView txtValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
txtValue = (TextView)findViewById(R.id.txtValue);
btnClick = (Button)findViewById(R.id.btnClick);
txtValue.setInputType(InputType.TYPE_NULL);
btnClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(txtValue.getInputType()==InputType.TYPE_NULL){
txtValue.setInputType(InputType.TYPE_CLASS_TEXT);
txtValue.invalidate();
btnClick.setText("Disable Input");
}else{
txtValue.setInputType(InputType.TYPE_NULL);
txtValue.invalidate();
btnClick.setText("Enable Input");
}
}
});
}
}