2011-04-13 69 views
1

我試圖居中位於LinearLayout中的兩個textView。這個LinearLayout嵌套在另一個ListView元素中。在LinearLayout中居中2文本視圖,僅在滾動時顯示文本

我想我的XML非常正確。我在我的Adapter類中動態填充textView。 XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:orientation="vertical"> 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:gravity="center"> 

    <TextView android:layout_height="wrap_content" 
    android:id="@+id/atlVacaturesnummer" 
    android:layout_width="wrap_content" 
    android:textColor="@color/Accent" 
    android:text="x" 
    /> 


    <TextView android:layout_height="wrap_content" 
    android:id="@+id/atlVacatures" 
    android:layout_width="wrap_content" 
    android:text="y" 
    /> 

    </LinearLayout> 

    <ListView android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:drawSelectorOnTop="false" /> 

    <TextView android:layout_height="fill_parent" 
    android:id="@+id/android:empty" 
    android:layout_width="fill_parent" 
    android:text="Er zijn geen jobs die voldoen aan uw criteria..." 
    android:gravity="center"/> 

</LinearLayout>  

Adapterclass:

/* 
* Klasse VacatureAdapter 
*/ 
private class VacatureAdapter extends ArrayAdapter<Vacature>{ 
    private ArrayList<Vacature> vacatures; 


    public VacatureAdapter(Context context, int textViewResourceId, ArrayList<Vacature> vacatures){ 
     super(context, textViewResourceId, vacatures); 
     this.vacatures = getArray(); 
     //System.out.println("Array vacatureadapter: " + v); 
    } 

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

     View view = convertview; 
     if(view==null){ 
      LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view = vi.inflate(R.layout.vacature_list_item, null); 
      //view.setBackgroundColor((position % 2) == 1? Color.LTGRAY: Color.WHITE); 
     } 

     TextView atlVacatures = (TextView)findViewById(R.id.atlVacatures); 
      TextView atlVacaturesnr = (TextView)findViewById(R.id.atlVacaturesnummer); 
      atlVacaturesnr.setText("" + arrVacatures.size()); 
      atlVacatures.setText(" jobs op maat gevonden!"); 

     Vacature vaca = vacatures.get(position); 

     if(vaca != null){    
      TextView tvNaam = (TextView) view.findViewById(R.id.vacatureNaam); 
      TextView tvWerkveld = (TextView) view.findViewById(R.id.vacatureWerkveld); 
      TextView tvRegio = (TextView) view.findViewById(R.id.vacatureRegio); 
     if(tvNaam != null){ 





      tvNaam.setText(vaca.getTitel()); 
      if(tvWerkveld != null){ 
       tvWerkveld.setText("Werkveld: " + vaca.getWerkveld()); 
       if(tvRegio!=null){ 
        tvRegio.setText("Regio: "+vaca.getRegio()); 
       } 
      } 
     } 
     } 
     return view; 
    } 
} 

奇怪的是,如果我的飛旋的運行,他顯示了我的XML設置正確的文本,如果旋轉停止,充滿了我的ListView那隻能說明我的號碼的一個數字,當我滾動一次,他完全顯示我的號碼加上第二個TextView。我不太明白有什麼不對,也許有些代碼需要放在別的地方?

+0

也許你可以包括一個截圖,清楚地顯示問題。當我無法想象問題是什麼時,很難理解。 – 2011-04-13 09:49:43

回答

1

我解僱了我的對話框後,通過將我的setText代碼放入Runnable方法中解決了我的問題。現在它看起來像這樣:

private Runnable returnRes = new Runnable(){ 
    public void run(){ 
     if (arrVacatures.size() == 0){ 
      dialog.dismiss(); 
     } 
     if(arrVacatures!=null && arrVacatures.size() > 0){ 
      adapter.notifyDataSetChanged(); 
      for(int i= 0; i< arrVacatures.size();i++){ 
       adapter.add(arrVacatures.get(i)); 
      } 
      dialog.dismiss(); 


      TextView atlVacatures = (TextView)findViewById(R.id.atlVacatures); 
      TextView atlVacaturesnr = (TextView)findViewById(R.id.atlVacaturesnummer); 
      atlVacaturesnr.setText("" + arrVacatures.size()); 
      atlVacatures.setText(" jobs op maat gevonden!"); 

      adapter.notifyDataSetChanged(); 
     } 
    } 
}; 
相關問題