2016-10-14 7 views
1

ListViewEditTextを行レイアウトで使用しました。私はEditTextを作成時に無効にし、ボタン "EDIT"をクリックして編集可能にします。テキストを更新した後、ユーザは「SAVE」ボタンをクリックして再び編集不能にすることができる。対応するEditTextを編集可能にする問題に直面しています。有効になりますが、フォーカスが得られず、ソフトキーボードも表示されません。私はここで何か間違っていますか?リストビューのedittextを無効にして有効にします

//Adapter class button click:- 
 

 
holder.edit.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 
       holder.count.setEnabled(true); 
 
       holder.count.setInputType(InputType.TYPE_CLASS_NUMBER); 
 
       holder.count.setFocusable(true); 
 
       holder.count.requestFocus(); 
 
       InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); 
 
       imm.showSoftInput(holder.count, InputMethodManager.SHOW_FORCED); 
 
       holder.edit.setVisibility(View.GONE); 
 
       holder.save.setVisibility(View.VISIBLE); 
 
      } 
 
     }); 
 
holder.save.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 
       holder.count.setEnabled(false); 
 
       holder.edit.setVisibility(View.VISIBLE); 
 
       holder.save.setVisibility(View.GONE); 
 
      } 
 
     });
//row layout xml:- 
 

 
<?xml version="1.0" encoding="utf-8"?> 
 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:background="#ffb3ff"> 
 

 
    <LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:orientation="horizontal"> 
 

 

 

 
     <EditText 
 
      android:id="@+id/count" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:layout_weight="1" 
 
      android:ellipsize="end" 
 
      android:padding="10dp" 
 
      android:gravity="center_horizontal" 
 
      android:inputType="none" 
 
      android:enabled="false" 
 
      android:focusable="false"/> 
 

 
     <Button 
 
      android:id="@+id/edit" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:text="edit"/> 
 

 
     <Button 
 
      android:id="@+id/save" 
 
      android:layout_width="wrap_content" 
 
      android:layout_height="wrap_content" 
 
      android:text="save" 
 
      android:visibility="gone"/> 
 
    </LinearLayout> 
 

 
</FrameLayout>

+0

あなたはアダプターのリストを作成しました。もしあなたがBeanクラスを使用しているならば、新しいフィールドは "編集"タイプのブール値を追加し、クリックした後真と偽をセットし、EditTextのこの変数を編集可能にします。 –

答えて

2

してみてください。私はマニフェストのアクティビティにandroid:windowSoftInputMode="stateAlwaysHidden|adjustPan"を追加するだけでした。その後、setEnabled()で働いています。

+0

これは私のために働いた。ありがとう! –

0

InputMethodManager inputMethodManager = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE); 
     // only will trigger it if no physical keyboard is open 
     inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); 

でコード

InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); 
       imm.showSoftInput(holder.count, InputMethodManager.SHOW_FORCED); 

のこのスニペットを交換し、この後、あなたは、リスト内の別のビューにフォーカスを与える必要があります。

+0

働いていませんでした。 @Mohom – CodeAssasins

0

は、答えは実際にはかなり簡単だった

holder.count.setClickable(true); 
+0

'setClickable'も試しましたが、edittextをタッチしてテキストを変更すると、編集できなくなります。 @Rissmon – CodeAssasins

0

私はサンプルブラウザを自分で作成していたときに、同じ問題が発生していました。まず、編集テキストのフォーカスが削除されると入力を許可しないため、たとえそれを再びフォーカス可能にしても。

使用この代わりのsetEditable(偽):

holder.count.setFocus(false); 
holder.count.setClickable(false); 
holder.count.setCursorVisible(false); 

、あなたのTextView有効にする:それは私がコメントで知らせて動作するかどうか

holder.count.setFocus(true); 
holder.count.setFocusInTouchMode(true); 
holder.count.setClickable(true); 
holder.count.setCursorVisible(true); 

を...

関連する問題