我不知道我的EditText到底发生了什么!
我有一个TextView,一个EdiText和一个Button。
所需的逻辑是: 单击按钮时,将EditText设置为TextView的内容。 单击“完成”后,TextView将显示EditText的内容。
到目前为止,这是我的代码:
speech_text = (TextView) findViewById(R.id.speech);
speech_text_edit = (EditText) findViewById(R.id.speech_edit);
editBTN= (Button) findViewById(R.id.edit);
editBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
speech_text_edit.setText(speech_text.getText().toString());
speech_text.setVisibility(View.GONE);
speech_text_edit.setVisibility(View.VISIBLE);
//open keyboard
InputMethodManager show_imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
show_imm.showSoftInput(editBTN, InputMethodManager.SHOW_IMPLICIT);
speech_text_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
speech_text.setText(speech_text_edit.getText().toString());
speech_text_edit.setVisibility(View.GONE);
speech_text.setVisibility(View.VISIBLE);
speech_text_edit.setFocusable(false);
//close keyboard
InputMethodManager hide_imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
hide_imm.hideSoftInputFromWindow(editBTN.getWindowToken(), 0);
}
return true;
}
});
}
});
布局代码:
<TextView
android:id="@+id/speech"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_margin="25dp" android:layout_marginBottom="150dp"
android:textSize="25sp" android:textAlignment="inherit"
android:background="@drawable/curved_background"
android:textIsSelectable="true"
android:padding="10dp" android:visibility="visible"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="350dp"
android:id="@+id/speech_edit"
android:background="@drawable/curved_background"
android:imeActionLabel="actionDone"
android:visibility="gone"
android:textSize="25sp"
android:layout_margin="25dp" android:layout_marginBottom="150dp"
android:inputType="textAutoCorrect"
android:layout_gravity="top"
android:focusable="true"/>
我的问题是:
感谢您的帮助。
这是logCats:
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper
D/SensorManager: unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@4215f0c8
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper D/Sensors: Remain listener = Sending .. normal delay 200ms
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper I/Sensors: sendDelay --- 200000000
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper D/SensorManager: JNI - sendDelay
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper I/SensorManager: Set normal delay = true
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper D/SensorManager: registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@4215de80
05-14 19:26:45.050 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
05-14 19:26:45.065 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
05-14 19:26:45.080 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
05-14 19:26:45.080 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
05-14 19:26:45.080 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
05-14 19:26:45.100 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
05-14 19:26:45.100 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: setComposingText on inactive InputConnection
05-14 19:26:45.100 15484-15484/type_helper.maxsoft.com.typehelper W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
05-14 19:27:01.140 15484-15484/type_helper.maxsoft.com.typehelper D/SensorManager: unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@4215de80
05-14 19:27:01.140 15484-15484/type_helper.maxsoft.com.typehelper D/Sensors: Remain listener = Sending .. normal delay 200ms
05-14 19:27:01.140 15484-15484/type_helper.maxsoft.com.typehelper I/Sensors: sendDelay --- 200000000
05-14 19:27:01.140 15484-15484/type_helper.maxsoft.com.typehelper D/SensorManager: JNI - sendDelay
05-14 19:27:01.140 15484-15484/type_helper.maxsoft.com.typehelper I/SensorManager: Set normal delay = true
答案 0 :(得分:1)
TextView#setFocusable(true);
TextView#requestFocus();
在显示键盘之前。
InputMethodManager#showSoftInput( FOCUSED_VIEW, 0 );
删除
TextView.setFocusable(false);
FOCUSED_VIEW
应该是您的speed_edit_text
!不是按钮。
另外,请确保将EditText
的以下属性设置为启用多行输入:
android:inputType="textAutoCorrect|textMultiLine"
android:layout_gravity="top"
android:lines="8"
android:gravity="top|start"
android:minLines="6"
android:maxLines="10"
android:scrollbars="vertical"
min,max和lines值是任意数字,但您可以使用它来设置框高度的域。
问题是您致电TextView#setFocusable(false)
。当您将其设置为false时,您也会失去对此元素的关注。所以现在当你再次显示它时,Android并不知道显示键盘的原因(因为EditText
在显示时不会自动聚焦)。由于您隐藏了视图,因此您真的不需要使其无法重点,它GONE
因此无法集中注意力。
View#requestFocus
)View#clearFocus
)您可以使用以下三个值之一显示键盘:
EditText
SHOW_IMPLICIT
):用户不直接要求SHOW_FORCED
):强制显示,直到用户强迫&#34;它关闭您可以使用以下三个值之一隐藏键盘:
EditText
HIDE_IMPLICIT
):如果它显示为SHOW_IMPLICIT
HIDE_NOT_ALWAYS
):隐藏,除非显示SHOW_FORCED
但是,你可以强迫你想要的一切。如果一个元素不可聚焦,你就不会通过显示键盘来获得自动聚焦。
答案 1 :(得分:0)
Dim pCustID As String = "8000"
Dim RootDir As New DirectoryInfo(CustPdfPath)
Dim dirs() As DirectoryInfo
dirs = Array.FindAll(RootDir.GetDirectories, Function(x) x.Name.StartsWith(pCustID))
Dim myDir As DirectoryInfo = Array.Sort(RootDir.GetDirectories, _
Function(x As DirectoryInfo, y As DirectoryInfo) _
x.Name.Length > y.Name.Length).firstordefault