2015-01-13 2 views
0

이미 비슷한 질문을 읽었지만 문제가 해결 된 해결책이 없으므로 중복으로 표시하지 마십시오. EditText가 ListView에서 포커스를 잃음

은 내가 ListFragment custom ArrayListAdapter을 통해 채워진 ListView를 포함 FrameLayout 로모그래퍼 있습니다. 목록의 각 행에는

Checkbox, EditTextImageButton의 세 가지 요소가 있습니다.

내 문제는 내가 EditText을 변경하면 키보드가 포함되어 있지만 초점이 즉시 사라져서 쓸 수 없음을 나타냅니다.

나는 이미 manifest 파일에 내 Activity

안드로이드를 추가 한 점에 유의하시기 바랍니다 : windowSoftInputMode = "adjustResize"

을 심지어

안드로이드 : descendantFocusability = " afterDescendants " android : descendantFocusability ="beforeDescendants "

이 문제를 해결하지 못합니다. 여기

내 XML 코드 :

row_item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
> 

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/item_checkbox" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    /> 

<EditText 
    android:id="@+id/item_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="60px" 
    android:text="Test text" 
    android:singleLine="true" 
    android:layout_toRightOf="@id/item_checkbox" 
    android:layout_centerVertical="true" 
    android:layout_toLeftOf="@+id/item_important" 
    android:layout_toStartOf="@+id/item_important" /> 

<ImageButton 
    android:id="@+id/item_important" 
    android:layout_width="20dip" 
    android:layout_height="20dip" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_marginRight="10dp" 
    android:visibility="visible" 
    android:layout_marginLeft="10dp" /> 

</RelativeLayout> 

fragment_list.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="8dp" 
    android:paddingRight="8dp" 
    > 

    <ListView android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    /> 

</FrameLayout> 

어디 방법을 이해하는 방법 좀 자원을 제안 할 수 있다면 그것은 좋은 것입니다 이 경우에는 집중력이 작용합니다.

는 당신에게 감사


나는 문제가 나타나지 키보드에 의해 생성된다 발견

업데이트 : 내가보기 재활용이 EditText 포커스를 잃을 이유입니다 같아요.

+0

가능한 중복의 문제 http://stackoverflow.com/questions/2679948/focusable-edittext-inside-listview – Abdellah

+0

했다 보인다 ... – Alessandro91

답변

0

이 코드

row_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

<CheckBox 
    android:id="@+id/item_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:focusable="false"/> 

<EditText 
    android:id="@+id/item_text" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_toLeftOf="@+id/item_important" 
    android:layout_toRightOf="@id/item_checkbox" 
    android:layout_toStartOf="@+id/item_important" 
    android:minHeight="60px" 
    android:focusable="true" 
    android:singleLine="true" /> 

<ImageButton 
    android:id="@+id/item_important" 
    android:layout_width="20dip" 
    android:layout_height="20dip" 
    android:layout_alignParentRight="true" 
    android:layout_centerVertical="true" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:visibility="visible" /> 

</RelativeLayout> 

fragment_list.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="8dp" 
android:paddingRight="8dp" 
> 

<ListView 
    android:id="@id/android:list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:descendantFocusability="beforeDescendants"/> 

</FrameLayout> 

활동 코드

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fragment_list); 

    ArrayList<String> mArrayList = new ArrayList<String>(); 
    /**mArrayList.add("Test"); 
    mArrayList.add("Test"); 
    mArrayList.add("Test"); 
    mArrayList.add("Test");**/ 

    CustomeAdapter adapter = new CustomeAdapter(this, mArrayList); 
    ListView listView = (ListView) findViewById(android.R.id.list); 
    listView.setItemsCanFocus(true); 
    listView.setAdapter(adapter); 
} 

public class CustomeAdapter extends ArrayAdapter { 

    ArrayList<String> mArrayList; 
    @SuppressWarnings("unchecked") 
    public CustomeAdapter(Context context, ArrayList<String> users) { 
     super(context, R.layout.row_item, users); 
     mArrayList = new ArrayList<String>(); 
     mArrayList = users; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     ViewHolder viewHolder; // view lookup cache stored in tag 
     if (convertView == null) { 
      viewHolder = new ViewHolder(); 
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_item, parent, false); 
      viewHolder.mCheckBox = (CheckBox) convertView.findViewById(R.id.item_checkbox); 
      viewHolder.mEditText = (EditText) convertView.findViewById(R.id.item_text); 
      viewHolder.mImageView = (ImageView) convertView.findViewById(R.id.item_important); 

      convertView.setTag(viewHolder); 
     } else { 
      viewHolder = (ViewHolder) convertView.getTag(); 
     } 
     viewHolder.mEditText.setText(mArrayList.get(position)); 
     return convertView; 
    } 

    // View lookup cache 
    private class ViewHolder { 
     CheckBox mCheckBox; 
     EditText mEditText; 
     ImageView mImageView; 
    } 
} 
,536 시도
+0

고맙습니다. Android API 16을 사용하여 모바일 장치에서 코드를 실행했지만 여전히 동일한 문제가 있습니다. 그런 다음 Android API 21을 사용하여 가상 장치에서 테스트했으며 작동합니다. 왜 그런지 알아? – Alessandro91

1

새로운 RecyclerView 클래스를 사용하여 문제를 해결했습니다.불행하게도 문제를 해결하지 않는, 즉 내가 이미 솔루션을 시도 ListView

관련 문제