旋转器仍为空

时间:2015-10-19 00:56:50

标签: android spinner

我在BaseAdapter

上创建了一个微调器

但是当我选择一个值仍然是空的时候

这是我的代码

SpinnerAdapter.class

public class SpinnerAdapter extends BaseAdapter {

    private List<School> schools;
    private Activity parentActivity;
    private LayoutInflater inflater;

    public SpinnerAdapter(Activity parent, List<School> l) {
        parentActivity = parent;
        schools = l;
        inflater = (LayoutInflater) parentActivity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    @Override
    public int getCount() {
        return schools.size();
    }

    @Override
    public Object getItem(int position) {
        return schools.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (convertView == null)
            view = inflater.inflate(R.layout.row_spinner, null);

        TextView text1 = (TextView) view.findViewById(R.id.id);
        TextView text2 = (TextView) view.findViewById(R.id.libelle);
        School myObj = schools.get(position);
        text1.setText(String.valueOf(myObj.get_id()));
        text2.setText(myObj.get_nom());
        text1.setVisibility(View.GONE);

        return view;
    }
}

School.class

public class School {

    private int _id;
    private String _nom;


    public int get_id() {
        return _id;
    }

    public void set_id(int _id) {
        this._id = _id;
    }

    public String get_nom() {
        return _nom;
    }

    public void set_nom(String _nom) {
        this._nom = _nom;
    }
}



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/libelle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"/>

</LinearLayout>

我使用volley库创建了一个从json文件中获取数据的请求

这是我的结果

enter image description here

但是当我选择一个值样式alwsays像这样空白时

enter image description here

感谢您的帮助

0 个答案:

没有答案