2012-03-19 3 views
0

에 추가 뷰 표시 할 수 없습니다제대로이 내 메인 레이아웃입니다 런타임

private void mimicListAdapter(List<Event> eventsList, String filters) { 

    TextView minute; 
    ImageView event_key; 
    TextView event_text; 
    LayoutInflater inflater = getLayoutInflater(); 
    LinearLayout container = (LinearLayout) findViewById(R.id.match_list); 

    for(Event p:eventsList) { 
     //LayoutInflater inflater = getLayoutInflater(); 
     View rowView = inflater.inflate(R.layout.match_event, null, true); 
     minute = (TextView) rowView.findViewById(R.id.minute); 
     event_key = (ImageView) rowView.findViewById(R.id.event_img); 
     event_text = (TextView) rowView.findViewById(R.id.event_text); 
     boolean found = false; 
     String[] events = getResources().getStringArray(R.array.filtering); 
     if(filters!=null) 
     { 
      if(filters!="") 
      { 
       char[] indici = filters.toCharArray(); 
       for(int i = 0; i<indici.length; i++){ 
        if(events[Character.getNumericValue(indici[i])].contains(","+p.getEventKey()+",")) 
        { 
         found=true; 
         break; 
        } 
       } 
      } 

     } 
     minute.setText(Integer.toString(p.getMinute())); 
     event_text.setText(p.getEventText()); 
     try { 
      Drawable img = getResources().getDrawable(getResources().getIdentifier("i_"+p.getEventKey(), "drawable", getPackageName())); 
      event_key.setImageDrawable(img); 
     } catch (Exception e) { 

     } 

     if(found) { 
      event_text.setTextColor(0xFFFF0000); 
      minute.setTextColor(0xFFFF0000); 
      found = false; 
     } 

     container.addView(rowView); 
    } 
} 

문제 나는 밖에있는 것이 무엇이든간에 match_list이 표시되어 있습니다. c orrectly, match_list 안쪽에서 첫 번째 요소를 볼 수는 있지만 모두 비어 있습니다. 제 말은 LinearLayout이 채워진 것처럼 보입니다. 왜냐하면 많은 디스플레이를 차지하기 때문에 Line2Layout은 첫 번째로 Event 만 보이는 검은 색 공간 일뿐입니다.

답변

1

컨테이너에보기를 추가 할 때 LayoutParams 클래스를 사용하여 표시해야하는 방법에 대한 정보를 전달해야합니다. 레이아웃 xml에서 layout_widht 및 layout_height를 사용하여 정의 된 정보가 누락되었습니다. 그들 없이는 안드로이드는 첫 번째보기를 설정하지만 크기 정보가 누락되면 다른보기를 정렬하지 못한다고 생각합니다. 이 같은 것 :

container.addView(rowView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
+0

아니요 ... 같은 문제. 그것은 아주 이상합니다. – dierre