在我的应用程序中,我正在搜索模块我之前的问题是如何在其他活动中显示json响应?我在服务器中发送请求,然后我得到响应并作为响应我得到一些数据,我希望显示的数据下一页,我不知道怎么做,可以帮助吗?
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
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);推荐答案
显示下一个活动的响应可以通过以下方式完成
show response in next activity can be done in following ways
解决方案1 响应来自字符串,因此使用
Solution 1 response comes in string so pass whole response to next activity by using
intent.putExtras("Key",response);解决方案2 通过使用此类制作单例类的getter setter你可以在我们的应用程序中设置和获取值。
Solution 2 make a singleton class of getter setter , by using this class u can set and get values throughout our application .
喜欢这个
第1步
public class SingleObject { //create an object of SingleObject private static SingleObject instance = new SingleObject(); private String name; private String age; //make the constructor private so that this class cannot be //instantiated private SingleObject(){} //Get the only object available public static SingleObject getInstance(){ return instance; } // here u can declare getter setter public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } }第2步使用它在第一个这样的活动中
step 2 use it in first activity like this
Singleton tmp = Singleton.getInstance( ); tmp.setName("");第3步
以及下一项活动像这样
Singleton tmp = Singleton.getInstance( ); String name = tmp.getName;解决方案3 :制作一个静态的hashmap Arraylist并在任何地方使用它活动
Solution 3 : Make a static Arraylist of hashmap and use it in any activity
或者可能有更多解决方案......
or there may be more solutions .....
更多推荐
如何在下一个活动中显示响应
发布评论