Reputation: 4594
I have populated a spinner with some data, like this:
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;
}
}
That is a part of my code. This is how the spinner looks:
This is ok.
But when I click on it I looks like this:
It doesn't show the same data as in the state when it is not selected!!!!
Data that should be displayed when selected should be : 2012-09-03 second 11
. Anyone can tell me where I'm going wrong??? and what is the solution. Thx
Upvotes: 1
Views: 107
Reputation: 328598
You should override toString
in your UserComments
class, for example:
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;
}
}
Upvotes: 3
Reputation: 152216
In UserComments
override toString
method and return text you want to be visible in your spinner.
Upvotes: 3