How can i get Array of objects in a Array of string Format to assign to List View in Android?
i am getting a Array of objects from a webservice which has to be assigned to ArrayAdapter to be listed in a listView, i getting the result in @431d5410 in this format, How can i get in a string Format?
projects = projectService.SearchProjects("", 0, -1);
**Vector<ADSProject> ProjList = projects.getResults();**
setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,ProjList));
ListView Projects = getListView();
Projects.setOnItemClickListe开发者_如何学Goner(this);
The ArrayAdapter is trying to fill your listview with the ADSProject Object (hence the @431d5410.) You should make a custom ArrayAdapter or BaseAdapter and handle retrieving the String value from your ADSProject Object yourelf.
It would look something like this (Not sure if this works with a Vector Object however, I would use ArrayList):
public class MyArrayAdapter extends ArrayAdapter<ADSProject> {
private Context mContext;
private List<ADSProject> mProjects;
private int mLayoutResource;
private int mTextViewResourceId;
private TextView mTextView;
public MyArrayAdapter(Context context, int resource,
int textViewResourceId, List<ADSProject> objects) {
super(context, resource, textViewResourceId, objects);
mContext = context;
mLayoutResource = resource;
mTextViewResourceId = textViewResourceId;
mProjects = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Handle View Recycling
View view;
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(mLayoutResource, null);
} else {
view = convertView;
}
// Get textview and set with string from ADSProject Object
mTextView = (TextView)view.findViewById(mTextViewResourceId);
mTextView.setText(mProjects.get(position).getStringValue());
return view;
}
}
精彩评论