0

Java Bean Class

package com.app.deallocator;

public class JavaBean {
String val1;

public String getVal1() {
    return val1;
}

public void setVal1(String val1) {
    this.val1 = val1;
}

}
 Class MainActivity
protected Void doInBackground(Void... arg0) {
            // Creating service handler class instance
            MyCollectionServices sh = new MyCollectionServices();

            // Making a request to url and getting response
            ArrayList list = new ArrayList<JavaBean>();

            list = sh.makeServiceCall(url, getBaseContext());

            Log.d("Response: ", "> " + mybean);



            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            // Dismiss the progress dialog
            pDialog.dismiss();

            if (list != null) {
                ArrayList<String> l = new ArrayList<String>();
                for(int i=0; i<list.size(); i++){
                    String s = String.valueOf(list.get(i).toString());
                    l.add(s);
                    Log.d("GetCategoryMain",""+ s);

                }

                ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(MainActivity.this,
                        android.R.layout.simple_spinner_item, l);

                dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                //set the ArrayAdapter to the spinner
                spin.setAdapter(dataAdapter);
                //attach the listener to the spinn

        } else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }

Getting the result as,

com.app.deallocator.JavaBean@40ce3210,

com.app.deallocator.JavaBean@40ce3210,

com.app.deallocator.JavaBean@40ce3210,

How to convert it to string and retrieve its value.

1 Answers1

3

On your JavaBean class override the toString() method as like here and get the needed data from your class.

    package com.app.deallocator;

    public class JavaBean {

    String val1;

    public String getVal1() {
        return val1;
    }

    public void setVal1(String val1) {
        this.val1 = val1;
    }

    @Override
    public String toString() {
        return val1;
    }

}

For more details refer here.

ashokramcse
  • 2,841
  • 2
  • 19
  • 41