Android : Display the HTTPentity response value in ListView android

on Saturday, January 31, 2015


I need to display the HttpEntity response values in the listview Here is my code



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
// we will using AsyncTask during parsing
new AsyncTaskParseJson().execute();
}

// you can make this class as another java file so it will be separated from your main activity.
public class AsyncTaskParseJson extends AsyncTask<String, String, String> {

final String TAG = "AsyncTaskParseJson.java";

// contacts JSONArray
JSONArray dataJsonArr = null;

@Override
protected void onPreExecute() {}

@Override
protected String doInBackground(String... arg0) {
// post the specific format data to json url
Here am getting the response values

try {
HttpClient httpClient = new DefaultHttpClient();
JSONObject object = new JSONObject();
object.put("Username", "testUser@123");
object.put("Password", "testPassword@123");
JSONObject jsonObject = new JSONObject();
jsonObject.put("Authentication", object);
jsonObject.put("RequestType", 4);
HttpPost postMethod = new HttpPost("url");
postMethod.setEntity(new StringEntity(jsonObject.toString()));
postMethod.setHeader("Accept", "application/json");
postMethod.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(postMethod);
HttpEntity entity = response.getEntity();
String response_value = EntityUtils.toString(entity).toString();
// Log.e(TAG, response_value ); //display the output in logcat

if (entity != null) {
//Convert String to JSON Object
JSONObject result = new JSONObject(response_value);

JSONArray tokenList = result.getJSONArray("Files");


for(int i=0;i<=tokenList.length();i++)
{
JSONObject oj = tokenList.getJSONObject(i);
JSONObject oj1 = (JSONObject) tokenList.getJSONObject(i).get("Borrower");
JSONObject oj2 = (JSONObject) tokenList.getJSONObject(i).get("CoBorrower");
JSONObject oj3 = (JSONObject) tokenList.getJSONObject(i).get("LoanDetails");
JSONObject oj4 = (JSONObject) tokenList.getJSONObject(i).get("PropertyAddress");
String fileid = oj.getString("FileID");
String borrowername = oj1.getString("FirstName");
String coborrowername = oj2.getString("FirstName");
String loannumber = oj3.getString("LoanNumber");
String addrs1 = oj4.getString("Address1");
String city = oj4.getString("City");
Log.e(TAG, fileid + "/" + borrowername + "/"+ coborrowername + "/"+ addrs1 + "/"+ city + "/"+ loannumber );
JSONArray orders = oj.getJSONArray("Orders");

for(int n=0;n<orders.length();n++){

JSONObject oj5 = orders.getJSONObject(n);
String appid = oj5.getString("ApplicationOrderId");
String appid1 = oj5.getString("DueDate");
Log.e(TAG, appid +"/"+ appid1);


}
}

}


} catch (Exception e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(String strFromDoInBg) {}
}


} Now am displaying the response value in the log cat but i want to display this values in the List View. If you have any idea please help me, thanks in advance.


0 comments:

Post a Comment