我用一些数据填充了一个微调器,如下所示:
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;
}
}
这是我的代码的一部分。这是微调器的外观: here is my picture http://i46.tinypic.com/15ml8g1.png
没关系。
但是当我点击它时,我看起来像这样: here is my image http://i46.tinypic.com/2zhlahw.png
它没有显示与未选择状态时相同的数据!
选择时应显示的数据应为:2012-09-03 second 11
。任何人都可以告诉我哪里出错了???什么是解决方案。 THX
答案 0 :(得分:3)
在UserComments
覆盖toString
方法并返回您希望在微调器中显示的文字。
答案 1 :(得分: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;
}
}