tags:

views:

81

answers:

1

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.setOnItemClickListener(this);
+2  A: 

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;
  }

}
disretrospect
A Vector is-a List, so using a Vector shouldn't be a problem.
Mayra
setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,ProjList));is there any thing here which can take all the list in string format or which directly displays the data?
Srikanth Naidu
Does ADSProject have a String variable inside it that you want to print in your list? If so you could build a new List of just the Strings by iterating through your Vector.
disretrospect
projects.getResults(); ADSProject returns vector (Array Of Objects) which contains projects
Srikanth Naidu
Yes, and what part of the project object do you want to show in your list?
disretrospect
Project name to be diplayed
Srikanth Naidu
Ok so I would either follow the example above and make a custom ArrayAdapter or I would iterate through your Vector and create a new List that just contains the project names. Then pass that to your standard ArrayAdapter
disretrospect