Vote count:
0
I want to show Arraylist of JSON format in TableLayout. TableLayout is dynamic and used in OnPost method of AsyncTask. How to get Data From ArrayList into TableLayout.This Is my activity in which I am using the Tablelayout. want to Show ArrayList in Tablelayout, ArrayList with the name of ContactList. thanks for the HElp
public class DailyMonthlyPerActivity extends Activity implements OnClickListener {
/////...VARIABLES...//////////////////
String month,week;
Button btnShowRpt;
UserFunction userFunction;
//JSONObject json,json_user;
private ProgressDialog pDialog;
private static String url = "http://ift.tt/1CS5XmG" ;
TableLayout tl;
TableRow itemsName ;
TextView tvItemName0 ;
TextView tvItemName1 ;
TextView tvItemName2;
private static final String TAG_CONTACTS = "Address";
private static final String TAG_DATA = "Name";
private static final String TAG_ID = "Name";
private static final String TAG_NAME = "Name";
private static final String TAG_EMAIL = "Age";
private static final String TAG_ADDRESS = "Name";
private static final String TAG_GENDER = "Name";
private static final String TAG_PHONE = "Age";
private static final String TAG_PHONE_MOBILE = "Name";
private static final String TAG_PHONE_HOME = "Name";
private static final String TAG_PHONE_OFFICE = "Name";
ArrayList<HashMap<String, String>> contactList;
////////////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_monthly_per);
contactList= new ArrayList<HashMap<String,String>>();
itemsName = new TableRow(this);
tvItemName0 = new TextView(this);
tvItemName1 = new TextView(this);
tvItemName2 = new TextView(this);
tl = (TableLayout)findViewById(R.id.tableLayoutLocationSaleandRecovery);
btnShowRpt = (Button)findViewById(R.id.btnShowReports);
btnShowRpt.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()== R.id.btnShowReports)
{
new GetContacts().execute();
}
}
private class GetContacts extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(DailyMonthlyPerActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
if (jsonStr != null) {
try {
JSONArray jsonObj = new JSONArray(jsonStr);
// looping through All Contacts
for (int i = 0; i < jsonObj.length(); i++) {
JSONObject c = jsonObj.getJSONObject(i);
String name = c.getString("Name");
String email = c.getString("Age");
String address = c.getString("Address");
// tmp hashmap for single contact
HashMap<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => value
//contact.put(TAG_ID, id);
contact.put(TAG_NAME, name);
contact.put(TAG_EMAIL, email);
contact.put(TAG_CONTACTS, address);
// adding contact to contact list
contactList.add(contact);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
itemsName.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT));
tl.addView(itemsName, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.MATCH_PARENT));
tvItemName0.setText(TAG_NAME);
tvItemName1.setText(TAG_EMAIL);
tvItemName2.setText(TAG_CONTACTS);
itemsName.addView(tvItemName0);
itemsName.addView(tvItemName1);
itemsName.addView(tvItemName2);
}
}
}
asked 2 mins ago
How to show data in TableLayout in post Method of AsyncTask
Aucun commentaire:
Enregistrer un commentaire