1

我用一些数据填充了一个微调器,如下所示:

adapter =
newSpinAdapter(this,com.Orange.R.layout.spinnerrowlist,spinnerInfo);                  adapter.setDropDownViewResource(com.Orange.R.layout.multiline_spinner_dropdown_item);
previousVisitCommentsSpinner.setAdapter(adapter);

public class UserComments {
    public String coach;
    public String comment;
    public String date;

    public UserComments(String coach, String comment, String date) {
        this.coach = coach;
        this.comment = comment;
        this.date = date;
    }
}

    public class SpinAdapter extends ArrayAdapter<UserComments>{
        private Context context;
        private ArrayList<UserComments> spinnerInfo;

        public SpinAdapter(Context context, int textViewResourceId, ArrayList<UserComments> spinnerInfo){
            super(context, textViewResourceId, spinnerInfo);
            this.spinnerInfo = spinnerInfo;
        }

        @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.spinnerrowlist, null);
    }

            Visit.UserComments info = spinnerInfo.get(position);

            if (info != null) {
        TextView spinneritem1 = (TextView) v.findViewById(R.id.textview_spinner1);
        TextView spinneritem2 = (TextView) v.findViewById(R.id.textview_spinner2);
                    TextView spinneritem3 = (TextView) v.findViewById(R.id.textview_spinner3);

        if (spinneritem1 != null) {
                        spinneritem1.setText(info.coach);
                        spinneritem1.setTextColor(getResources().getColor(
                            R.color.medium_gray));
        }

        if (spinneritem2 != null) {
                        spinneritem2.setText(info.comment);
                        spinneritem2.setTextColor(getResources().getColor(
                            R.color.medium_gray));
            }

                    if (spinneritem3 != null) {
                        spinneritem3.setText(info.date);
                        spinneritem3.setTextColor(getResources().getColor(
                            R.color.medium_gray));
            }

        }
            return v;
        }

    }

这是我的代码的一部分。这是微调器的外观: 这是我的照片

还行吧。

但是当我点击它时,我看起来像这样: 这是我的形象

显示的数据与未选中时的状态不同!!!!选择时应显示的数据应为:2012-09-03 second 11。谁能告诉我哪里出错了???什么是解决方案。谢谢

4

2 回答 2

3

UserComments覆盖toString方法和返回文本中,您希望在微调器中可见。

于 2012-08-31T09:25:44.287 回答
3

你应该toString在你的UserComments类中覆盖,例如:

public class UserComments {
    public String coach;
    public String comment;
    public String date;

    public UserComments(String coach, String comment, String date) {
        this.coach = coach;
        this.comment = comment;
        this.date = date;
    }

    @Override
    public String toString() {
        return date + " " + comment + " " + coach;
    }
}
于 2012-08-31T09:25:52.643 回答