2016-07-04 1 views
-1

내 xml 파일 :안드로이드 - 왜 ListView 내부의 ListView가 작동하지 않습니까?

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="" 
     android:id="@+id/address" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="" 
     android:layout_below="@+id/address" 
     android:id="@+id/win_title" /> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/win_list" 
     android:layout_below="@+id/win_title" 
     android:layout_weight="1" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="" 
     android:id="@+id/lose_title" /> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lose_list" 
     android:layout_weight="1" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="" 
     android:id="@+id/cannot_compare_title" /> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/cannot_compare_list" 
     android:layout_weight="1" /> 

</LinearLayout> 

그리고 이것은 내 사용자 지정 어댑터입니다 :

public class AnalysisResultAdapter extends ArrayAdapter<ComparisonResult> { 

    static class ViewHolder { 
     TextView address; 

     TextView win_title; 
     ListView win_list; 

     TextView lose_title; 
     ListView lose_list; 

     TextView cannot_compare_title; 
     ListView cannot_compare_list; 
    } 

    private Hashtable<String, SevenEleven[]> sevenElevenData; 

    public AnalysisResultAdapter(Context context, int resource, List<ComparisonResult> houses) { 
     super(context, resource, houses); 
    } 

    public void setSevenElevenData(Hashtable<String, SevenEleven[]> sevenElevenData) { 
     this.sevenElevenData = sevenElevenData; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View view = convertView; 
     ViewHolder holder; 

     if (view == null) { 
      LayoutInflater viewInflater; 
      viewInflater = LayoutInflater.from(getContext()); 
      view = viewInflater.inflate(R.layout.analysis_result_list_item, null); 

      holder = new ViewHolder(); 
      holder.address = (TextView) view.findViewById(R.id.address); 

      holder.win_title = (TextView) view.findViewById(R.id.win_title); 
      holder.win_list = (ListView) view.findViewById(R.id.win_list); 

      holder.lose_title = (TextView) view.findViewById(R.id.lose_title); 
      holder.lose_list = (ListView) view.findViewById(R.id.lose_list); 

      holder.cannot_compare_title = (TextView) view.findViewById(R.id.cannot_compare_title); 
      holder.cannot_compare_list = (ListView) view.findViewById(R.id.cannot_compare_list); 

      view.setTag(holder); 
     } else { 
      holder = (ViewHolder) view.getTag(); 
     } 

     if (this.sevenElevenData.size() == 0) { 
      return view; 
     } 

     ComparisonResult result = getItem(position); 
     holder.address.setText(result.house.Address); 

     if (result.win.size() > 0) { 
      ArrayList<String> storeNames = new ArrayList<String>(); 
      for (int storeIndex : result.win) { 
       storeNames.add(this.sevenElevenData.get(result.house.Area)[storeIndex].StoreName); 
      } 

      holder.win_title.setText("win"); 
      holder.win_list.setAdapter(new ArrayAdapter<String>(
       getContext(), 
       R.layout.text_list, 
       R.id.text_list, 
       storeNames 
      )); 
     } 

     if (result.lose.size() > 0) { 
      ArrayList<String> storeNames = new ArrayList<String>(); 
      for (int storeIndex : result.lose) { 
       storeNames.add(this.sevenElevenData.get(result.house.Area)[storeIndex].StoreName); 
      } 

      holder.lose_title.setText("lose"); 
      holder.lose_list.setAdapter(new ArrayAdapter<String>(
        getContext(), 
        R.layout.text_list, 
        R.id.text_list, 
        storeNames 
      )); 
     } 

     if (result.cannotBeCompared.size() > 0) { 
      ArrayList<String> storeNames = new ArrayList<String>(); 
      for (int storeIndex : result.cannotBeCompared) { 
       storeNames.add(this.sevenElevenData.get(result.house.Area)[storeIndex].StoreName); 
      } 

      holder.cannot_compare_title.setText("cannotBeCompared"); 
      holder.cannot_compare_list.setAdapter(new ArrayAdapter<String>(
        getContext(), 
        R.layout.text_list, 
        R.id.text_list, 
        storeNames 
      )); 
     } 


     return view; 
    } 
} 

문제는 다음과 같습니다 만 @ + ID는/주소 텍스트 뷰 텍스트가 성공적으로 다른 상황이 표시되지 않습니다 보여줍니다. 그러나 나는 왜 이것이 일어 났는지 모른다.

이 문제를 어떻게 해결할 수 있습니까? 누군가 나를 도울 수 있습니까?

감사합니다.

+0

'ListView '가 스크롤 가능보기에서 높이를 가져올 수 없기 때문에. 중첩 된 ListView의 높이를 설정해야합니다 –

+0

콘텐츠 길이에 따라 높이를 설정하는 방법은 무엇입니까? – user3087000

+0

수 없습니다. 내 제안 : 중첩 된 Listview 대신 RecyclerView 사용 –

답변

0

1/layout_below는 RelativeLayout에서만 작동합니다. 가로 방향으로 LinearLayout을 사용하므로 모든 요소가 나란히 렌더링되고 모든 요소는 layout_width : "match_parent"를 가지므로 첫 번째 요소 만 표시됩니다.

2/당신이 두 번째

1

의 높이를 계산 할 수없는 또 다른있는 ScrollView의 렌더러를 ListView를 사용할 때 사용 있는 ScrollView 외부 (부모)의 ListView의 intead.

내부 ListView에 LisView를 사용하십시오.

스크롤 기능이 있습니다.

관련 문제