Я не знаю, что на самом деле происходит для моего EditText!редактировать тексты из текстового представления в текст редактирования в android
У меня есть TextView, EdiText и кнопка.
Необходима логика: Устанавливает 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"/>
Мои проблемы являются:
- работает только один раз! После этого нет клавиатуры и указателя.
- EditText показывает тексты только в одной строке в центре. Зачем?
Благодарим за помощь.
это logCats:
05-14 19:26:45.045 15484-15484/type_helper.maxsoft.com.typehelper
D/SensorManager: unregisterListener:: Listener= [email protected]15f0c8
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= [email protected]15de80
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= [email protected]15de80
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
Ваш лог-код не имеет ошибок, поэтому я не уверен, что вы пытаетесь показать –
нормально, я объясню еще раз. «Привет» написано в T.V. editBTN. Инопланетянин показать «Hello» с помощью клавиатуры и указателя. Я редактирую его в «Hello world». Сделано нажатие кнопки BTN, T.V. показывает «Hello world». все нормально. теперь время снова нажимаю editBTN. Инопланетянин «Hello world» тоже, но мягкая клавиатура и указатель не отображаются/запускаются. –
'setFocusable (false)' помешает вам снова ввести текст редактирования. – njzk2