Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Experimentation for Engineers: From A/B testing to Bayesian optimization
this week in the
Design
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
Java class with parameter
Wavix John
Greenhorn
Posts: 2
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi!
I have this
DownloadJSON
class initialized on
onCreate
with
new DownloadJSON().execute();
@Override protected Void doInBackground(Void... params) { arraylist = new ArrayList<HashMap<String, String>>(); jsonobject = JSONfunctions.getJSONfromURL("http://www.domain.com/json2.txt"); try { jsonarray = jsonobject.getJSONArray("worldpopulation"); for (int i = 0; i < jsonarray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); jsonobject = jsonarray.getJSONObject(i); map.put("rank", jsonobject.getString("rank")); arraylist.add(map); } } catch (JSONException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null;Below, depending where users clicks, I want to change jsonobject = JSONfunctions.getJSONfromURL("http://www.domain.com/json1.txt"); Something like this: } @Override protected void onPostExecute(Void args) { listview = (ListView) findViewById(R.id.listview); adapter = new ListViewAdapter(MainActivity.this, arraylist); listview.setAdapter(adapter); } }
Below, depending where users clicks, I want to change
jsonobject = JSONfunctions.getJSONfromURL("http://www.domain.com/json1.txt");
Something like this:
public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.itemone) { new DownloadJSON().execute("http://www.domain.com/json2.txt"); } else if (id == R.id.itemtwo) { new DownloadJSON().execute("http://www.domain.com/json3.txt"); } return true; }
How I can obtain this? I can't figure out how to do it.
Thanks!
Maneesh Godbole
Bartender
Posts: 11497
19
I like...
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
new DownloadJSON().execute("http://www.domain.com/json2.txt");
The value which you passed in the execute can be obtained like this
protected Void doInBackground(String... params) { String url = params[0]; arraylist = new ArrayList<HashMap<String, String>>(); jsonobject = JSONfunctions.getJSONfromURL(url); ... }
[
How to ask questions
] [
Donate a pint, save a life!
] [
Onff-turn it on!
]
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
can't we add two chicld elements to HorizontalScrollView
Problems with Servlet and Windows Playing Videos from Servlet
syntax for repeating a parameter in code?
how to print blance line
Execute method is not getting called in struts1
More...