У меня есть экран со списком, когда я нажимаю на элемент, я заменяю Textview с помощью EditText, показывая & сокрытие. Я могу скрыть TextView &, видимый EditText. Но после получения EditText видимым, он не показывает мягкую клавиатуру, как при нормальном поведении. Я попробовал другой ответ, чтобы отображать клавиатуру программно, но ничего не работало вообще.Как открыть клавиатуру в editText?
Это мой list.xml файл
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/settings_list_item"
android:orientation="vertical"
tools:context=".Setting" >
<TextView
android:id="@+id/tvHeader"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/gradient_bg_hover_holo"
android:gravity="center"
android:text="@string/settingTitle"
android:textColor="@color/white_smoke"
android:textSize="22sp" />
<ListView
android:id="@+id/list_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants" >
</ListView>
</LinearLayout>
Это мой list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/settings_list_item"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal" >
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:contentDescription="@null"
android:src="@drawable/ic_settings_1" />
<TextView
android:id="@+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/list_image"
android:text="@string/settings_item_1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<EditText
android:id="@+id/txtSelfDestroyCount"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/list_image"
android:focusable="true"
android:focusableInTouchMode="false"
android:hint="@string/selfDestoryCount"
android:imeOptions="actionDone"
android:inputType="numberSigned"
android:lines="1"
android:maxLength="1"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:visibility="gone" />
<ImageView
android:id="@+id/rightArrow"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:src="@drawable/ic_arrow" />
<ToggleButton
android:id="@+id/masterPasswordOption"
android:layout_width="60dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/master_password"
android:textColor="#000000"
android:visibility="gone" />
</RelativeLayout>
Это код, чтобы скрыть TextView & Отобразите EditText.
case 3:
{
TextView textView = (TextView) view.findViewById(R.id.txtItemName);
textView.setVisibility(View.INVISIBLE);
ImageView imageView = (ImageView) view.findViewById(R.id.rightArrow);
imageView.setVisibility(View.INVISIBLE);
final EditText editText = (EditText) view.findViewById(R.id.txtSelfDestroyCount);
editText.setVisibility(View.VISIBLE);
editText.setFocusableInTouchMode(true);
editText.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
System.out.println ("clicked ");
// Set keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
// Lets soft keyboard trigger only if no physical keyboard present
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
});
adapter.notifyDataSetChanged();
}
Когда я нажимаю на EditText, я могу видеть System.out.println ("clicked ");
на DDMS.
Пожалуйста, помогите мне.
Вы не должны обрабатывать событие OnClick для EditText, Android должна надуть клавиатуры по умолчанию. Попробуйте избавиться от вашего 'editText.setOnClickListener (...' – zgc7009
@ zgc7009, я пробовал, но ничего не получилось. – user2060383
Не могли бы вы опубликовать свой манифест? Возможно, вам нужно изменить это свойство внутри тегов активности: 'android: windowSoftInputMode = "stateVisible" ' –