Hello Android Developers,

    I want to show progressbar during web service request, get the JSON
response and make it listview . I tried Async but i don't know how to make
listview in onPostExecute method.
*
My sample code without ProgressDialog*:

public class HomeActivity  extends ListActivity {
   setContentView(R.layout.home);
  HttpGet httpget = new
HttpGet(getString(R.string.app_url)+"api/folders?authentication_token="+authentication_token+"&secret_token="+secret_token);
        httpget.addHeader("Accept","application/json");

        try {
            response = httpclient1.execute(httpget);
             HttpEntity resEntity = response.getEntity();
               if (resEntity != null) {
                   JSONArray jarr = new
JSONArray(EntityUtils.toString(resEntity));
                   data1 = new Vector<RowData>();
                   for(int i=0; i<jarr.length(); i++)
                   {
                       jObj =jarr.getJSONObject(i);
                       try {
                           folder_name.add(jObj.get("name").toString());
                           rd = new RowData(i,
jObj.get("_id").toString(),jObj.get("icon_name").toString(),jObj.get("name").toString());
                  } catch (ParseException e) {
                          e.printStackTrace();
                  }
              data1.add(rd);
                   }

               CustomAdapter adapter = new CustomAdapter(this,
R.layout.list,R.id.title, data1);
               setListAdapter(adapter);


                private class RowData {
        protected int mId;
        protected String mFolderid;
        protected String mIcon_name;
        protected String mName;
        RowData(int id,String folderid,String icon_name,String name){
                mId=id;
                mFolderid=folderid;
                mIcon_name = icon_name;
                mName=name;
        }
        public String toString() {
                        return mId+" "+mFolderid+" "+mIcon_name+" "+mName;
            }
     }
     private class CustomAdapter extends ArrayAdapter<RowData> {
         public CustomAdapter(Context context, int resource,int
textViewResourceId, Vector<RowData> data1) {
                 super(context, resource, textViewResourceId, data1);
         }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder holder = null;
         TextView title = null;
         TextView detail = null;
         ImageView i11=null;
         RowData rowData= getItem(position);
         if(null == convertView){
             convertView = mInflater.inflate(R.layout.list, null);
             holder = new ViewHolder(convertView);
             convertView.setTag(holder);
     }
     holder = (ViewHolder) convertView.getTag();
     title = holder.gettitle();
     title.setText(rowData.mName);
     String icon=rowData.mIcon_name.toLowerCase();
     i11=holder.getImage();
     int path=getResources().getIdentifier(icon,"drawable", "com.test123");
     i11.setImageDrawable(getResources().getDrawable(path));
     return convertView;
}


public class ViewHolder {
     private View mRow;
     private TextView title = null;
     private TextView detail = null;
     private ImageView i11=null;
     public ViewHolder(View row) {
             mRow = row;
     }
     public TextView gettitle() {
             if(null == title){
                     title = (TextView) mRow.findViewById(R.id.title);
         }
             return title;
     }
     public TextView getdetail() {
             if(null == detail){
                     detail = (TextView) mRow.findViewById(R.id.detail);
         }
             return detail;
     }
     public ImageView getImage() {
             if(null == i11){
                     i11 = (ImageView) mRow.findViewById(R.id.img);
         }
         return i11;
     }
    }
}
}

Please suggest me.


Thanks and Regards, Dhamodharan.N

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to