0

hi guys first time on stack overflow and I've got a problem. I'm getting a list of string from a server and passing it into an arraylist of strings, everything looks fine until i pass it to another class to act as my spinadapter then i get a code version of its position in the array and not my string.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category_select);

    ArrayList < String > categories = new ArrayList < String > ();
    PopulateSpinner(categories);
    Log.d(TAG, "before spin adapter");
    adapter = new SpinAdapter(this, android.R.layout.simple_spinner_item, categories);
}


private void PopulateSpinner(ArrayList < String > categories) {
    BufferedReader in = null;
    Log.d(TAG, "bufferReader");
    try {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        Log.d(TAG, "request");
        String Url = "http://www.youcode.ca/Lab02Servlet";
        Log.d(TAG, Url);
        Log.d(TAG, "Url");
        request.setURI(new URI(Url.toString() + "?Service=categories"));
        Log.d(TAG, "URI");
        HttpResponse response = client.execute(request);
        Log.d(TAG, "response"); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        Log.d(TAG, "in");
        String line = "";
        while ((line = in .readLine()) != null) {
            Log.d(TAG, line);
            CategoryItem temp = new CategoryItem();
            temp.SETcategorystring(line);
            categories.add(temp.toString());
        }
        /*for (String string : categories)  test the aray to see if it has the content
        {
            Log.d(TAG, string.toString());
        }*/
        Log.d(TAG, "after the while");
    }


    private Context context;
    private ArrayList < String > jitters;
    private static final String TAG = "SpinAdapterActivity";
    public SpinAdapter(Context context, int textViewResourceId, ArrayList < String > categories) {
        super(context, textViewResourceId, categories);
        this.context = context;
        this.jitters = categories;
    }@
    Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        CategorySelect activity = (CategorySelect) context;
        LayoutInflater inflater = activity.getLayoutInflater();

        View spinnerRow = inflater.inflate(R.layout.category_textview, null);
        TextView line = (TextView) spinnerRow.findViewById(R.id.Category_textview_id);

        line.setText((String)(jitters.get(position)));

        return spinnerRow;
    }
Vipul
  • 27,808
  • 7
  • 60
  • 75

1 Answers1

1

1.Change code here

Directly add string value to list.

   categories.add(temp.toString()); change to categories.add(line); 

2. Another Way

        CategoryItem temp = new CategoryItem();
        temp.SETcategorystring(line);
        categories.add(temp.getcategoryString().toString());
user2251725
  • 406
  • 1
  • 5
  • 18