0

당신의 도움이 필요합니다! OnItemClickListener 조각에서 작동하지 않습니다 (Multicolumn ListView)

난 조각 중 하나가 ListFragments가 스크롤 뷰 박스되는 여러 열 목록보기 포함 인 2 명 단편 (헤더 하나와 다중 열 목록에 대해 하나)을 포함하는 메인 활성을 갖는다. 이 ListFragment는 onItemClickListener 메서드를 재정의합니다. 뷰와 모든 것을 스크롤 할 수 있지만 listview를 클릭하면 리스너가 호출되지 않습니다!

저는 여러 가지 솔루션을 시도했습니다.보기에 대한 집중 가능성을 차단하는 것과 같지만 지금까지 아무 것도 작동하지 않았습니다. 어쩌면 너희들이 나를 도울 수있을거야.

두 조각을 포함하는 부모 활동

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="1" 
    android:descendantFocusability="blocksDescendants" 
    tools:context=".MainWindow" 
    > 

    <fragment 
     android:id="@+id/headerfragment" 
     android:name="lindcom.mobile.estock.fragments.ListHeaderFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:descendantFocusability="blocksDescendants" 
     /> 

    <fragment 
     android:id="@+id/unitlistfragment" 
     android:name="lindcom.mobile.estock.fragments.UnitsListFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:descendantFocusability="blocksDescendants" 
     /> 

</LinearLayout> 

입니다 내 다중 열 목록에 사용할 레이아웃 :

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:descendantFocusability="blocksDescendants" > 

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

     <TextView 
      android:id="@+id/unitsCol1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.40" 
      android:ellipsize="marquee" 
      android:maxLines="1" 
      android:scrollHorizontally="true" 
      android:singleLine="true" 
      /> 

     <TextView 
      android:id="@+id/unitsCol2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.40" 
      android:ellipsize="marquee" 
      android:maxLines="1" 
      android:scrollHorizontally="true" 
      android:singleLine="true" 
      /> 


     <TextView 
      android:id="@+id/unitsCol3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:ellipsize="marquee" 
      android:maxLines="1" 
      android:scrollHorizontally="true" 
      android:singleLine="true" 
      /> 
    </LinearLayout> 

</ScrollView> 

내가 가진 후 위의 레이아웃, 비동기 작업에 채워집니다 데이터를 가져 왔습니다.

ListAdapter adapter = new SimpleAdapter(
        fragment.getActivity().getBaseContext(), this.unitList, 
        R.layout.unit_list_item, new String[] { TAG_OWNER, TAG_NAME, 
          TAG_CONTENT }, new int[] { R.id.unitsCol1, R.id.unitsCol2, 
          R.id.unitsCol3 }); 


      fragment.setListAdapter(adapter); // Set the adapter to the listFragment 

다음에 클릭 리스너의 경우 간단히 t 그는 조각 :

public class UnitsListFragment extends ListFragment { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // Fetch stuff here 

    } 

    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) { 

     String type = l.getItemAtPosition(position).getClass().toString(); 

     Log.d("Item type was", type); 
      // THIS IS NEVER INVOKED :(


    }; 
} 

나는 많은 다른 것들을 시도했지만 어쩌면 너희들은 내가 간과했을지도 모를 간단한 수정을 볼 수있다.

도움이 될 것입니다. 감사!

+1

ScrollView에 ListView가 있다고합시다. 그럴까요? 그렇다면 행복 파트너십이 거의 없으며 이유가 될 수 있습니다. – NigelK

답변

2

레이아웃에서 스콜 뷰를 제거하거나 포커스가 맞지 않는 것으로 정의한 다음 다시 시도하십시오.

+0

와우, 정말 고마워! 정말 간단했습니다. 그게 어떻게 필요했는지 이해가 안되는데, 왜냐하면 OP에서 보이는 scrollView에 android : focusable = "false" android : focusableInTouchMode = "false" android : descendantFocusability = "blocksDescendants" 을 정의했기 때문이다. 나는 그것이 그렇게 간단하지 않다는 것을 믿을 수 없다. 어쨌든 나는 scrollview없이 살 수 있다는 것이 밝혀졌다. 고마워! –

관련 문제