0

У меня есть экран со списком, когда я нажимаю на элемент, я заменяю 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.

Пожалуйста, помогите мне.

+0

Вы не должны обрабатывать событие OnClick для EditText, Android должна надуть клавиатуры по умолчанию. Попробуйте избавиться от вашего 'editText.setOnClickListener (...' – zgc7009

+0

@ zgc7009, я пробовал, но ничего не получилось. – user2060383

+0

Не могли бы вы опубликовать свой манифест? Возможно, вам нужно изменить это свойство внутри тегов активности: 'android: windowSoftInputMode = "stateVisible" ' –

ответ

0

Изменить это свойство вашего редактирования текста, и он должен отобразить экранную клавиатуру:

android:focusableInTouchMode="true" 
+0

Уже пробовал это, но не работал. – user2060383

0

типа это свойство в вашем Activity tags внутри вашего manifest

android:windowSoftInputMode="stateVisible"

Больше об этой недвижимости here:

Ex достаточно:

<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . > 
0

В приложении я использую этот блок кода:

final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
+0

Я пробовал, это уже это тоже. – user2060383

Смежные вопросы