In my application,I am working on searching module my previous question is How to show json response in other activity? for that I send request in server and after that I am getting response and in response I get some data,and that data I want to display in next page,I dont know how to do that,can any one help?
class AttemptLogin extends AsyncTask<String, String, String> {
boolean failure = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Processing..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@SuppressWarnings("unused")
@Override
protected String doInBackground(String...args) {
//Check for success tag
//int success;
Looper.prepare();
String userids = strtext.toString();
String contri=spcountry.getText().toString();
String states=spstate.getText().toString();
String city=spcity.getText().toString();
System.out.println("Email : " + userids);
System.out.println("Email : " + agesfrom);
System.out.println("Days : " + agesto);
System.out.println("Months : " + heightfroms);
System.out.println("Years : " + heighttos);
System.out.println("User : " + language);
System.out.println("Password : " + religion);
System.out.println("Gender : " + marriage);
System.out.println("First NM : " + contri);
System.out.println("Last NM : " + states);
System.out.println("Profile : " + city);*/
try {
//Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_login_id", userids));
/* params.add(new BasicNameValuePair("age_from", agesfrom));
params.add(new BasicNameValuePair("age_to", agesto));
params.add(new BasicNameValuePair("height_from", heightfroms));
params.add(new BasicNameValuePair("height_to", heighttos));
params.add(new BasicNameValuePair("language", language));
params.add(new BasicNameValuePair("religion", religion));
params.add(new BasicNameValuePair("maritalstatus", marriage));
params.add(new BasicNameValuePair("country", contri));
params.add(new BasicNameValuePair("state", states));
params.add(new BasicNameValuePair("city", city));
*/
params.add(new BasicNameValuePair("version", "apps"));
Log.d("request!", "starting");
// getting product details by making HTTP request
json = jsonParser.makeHttpRequest (
SEARCH_URL, "POST", params);
//check your log for json response
Log.d("Request attempt", json.toString());
final String str = json.toString();
JSONObject jobj = new JSONObject(json.toString());
final String msg = jobj.getString("searchresult");
return json.getString(TAG_SUCCESS);
}catch (JSONException e) {
e.printStackTrace();
}
return null;
}
// After completing background task Dismiss the progress dialog
protected void onPostExecute(String file_url) {
//dismiss the dialog once product deleted
pDialog.dismiss();
Intent intent=new Intent(getActivity(),SearchResults.class);
intent.putExtra("id", strtext);
intent.putExtra("whole", json.getString(TAG_SUCCESS));
startActivity(intent);
}}
Searchresult.java
Id=this.getIntent().getStringExtra("id");
System.out.println("searching id"+Id);
results=this.getIntent().getStringExtra("whole");
System.out.println("Results"+results);
nomathc=(TextView)findViewById(R.id.no_match);
Broadcast notifications:
Then in SearchResult.java:
I believe that should do the trick.
Store the object in a static Variable that requires two Parameter (Object and Unique Key).
Searchresult.java
use
bundle
to move your response from one activity to another-create class that implements Parcelable
-Next save it in intent:
-step - retrive it:
-display it:
After that add it to an adapter to display it for the user
In other case you can save it in application context or database (not recommended)
I simply added hashmap and call it next activity its working fine,
in next activity
As far as I can see, all you need to know is how to bind your JSON result to a list view. If that's what you meant, read on...
I hope you already have a listview in your XML view for
SearchResults
activity. If not add one (sayR.id.listView1
).Then create a
row_listitem.xml
file to format how one item on the list looks like.Now you need to create a custom adapter (say
ResultAdapter
).Then you can modify your
SearchResults
activity.The code isn't checked for compilation errors. But you get the drift I guess. Cheers!
show response in next activity can be done in following ways
Solution 1 response comes in string so pass whole response to next activity by using
Solution 2 make a singleton class of getter setter , by using this class u can set and get values throughout our application .
like this
step 1
step 2 use it in first activity like this
step 3
and in next activity like this
Solution 3 : Make a static Arraylist of hashmap and use it in any activity
or there may be more solutions .....