开发者

Centering 2 Textviews in LinearLayout, text only shown when scrolling

I'm trying to center two textViews that are in a LinearLayout. This LinearLayout is nested in another one, with a ListView-element.

I think my XML is pretty correct. I fill my textViews dynamically in my Adapterclass. 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(vi开发者_如何学Goew==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;
    }
}

The weird thing is that if my spinner runs, he shows the texts set in my XML correctly, if the spinner stops and fills my ListView it only shows one digit of my number and when I scroll once he shows my number completly plus the second TextView. I don't quite understand what's wrong, maybe some code needs te be put somewhere else?


I've solved my problem by putting my setText code in my Runnable method, after I dismiss my Dialog. Now It looks like this:

    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();
        }
    }
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜