Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_comment);
- ActionBar actionbar = getSupportActionBar();
- actionbar.setDisplayHomeAsUpEnabled(true);
- abm = new ActionBarMenu(CommentActivityWp.this);
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
- userid = sp.getString("user_id", "none");
- Intent i = getIntent();
- // Receiving the Data
- ida = i.getStringExtra("id");
- url = "http://www.cepfonline.org/cepfblog/?json=1=" + ida;
- if (com.cepfmobileapp.org.service.InternetStatus.getInstance(this)
- .isOnline(this)) {
- // Toast t = Toast.makeText(this,"You are online!!!!",8000).show();
- // Toast.makeText(getBaseContext(),"You are online",Toast.LENGTH_SHORT).show();
- // Calling async task to get json
- new GetQuery().execute();
- } else {
- // Toast.makeText(getBaseContext(),"No Internet Connection",Toast.LENGTH_LONG).show();
- AlertDialog NetAlert = new AlertDialog.Builder(CommentActivityWp.this)
- .create();
- NetAlert.setMessage("No Internet Connection Found! Please check your connection and try again!");
- NetAlert.setButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- // here you can add functions
- // finish();
- }
- });
- NetAlert.show();
- }
- queryList = new ArrayList<HashMap<String, String>>();
- ListView lv = getListView();
- // Listview on item click listener
- lv.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- }
- });
- }
- /**
- * Async task class to get json by making HTTP call
- * */
- private class GetQuery extends AsyncTask<Void, Void, Void> {
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- // Showing progress dialog
- pDialog = new ProgressDialog(CommentActivityWp.this);
- pDialog.setMessage("Loading...comments");
- pDialog.setCancelable(false);
- pDialog.show();
- }
- @Override
- protected Void doInBackground(Void... arg0) {
- // Creating service handler class instance
- ServiceHandler sh = new ServiceHandler();
- // Making a request to url and getting response
- String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
- Log.d("Response: ", "> " + jsonStr);
- if (jsonStr != null) {
- try {
- JSONObject jsonObj = new JSONObject(jsonStr);
- // Getting JSON Array node
- comments = jsonObj.getJSONArray(TAG_COMMENTS);
- // looping through All Contacts
- for (int i = 0; i < comments.length(); i++) {
- JSONObject c = comments.getJSONObject(i);
- // Phone node is JSON Object
- //JSONObject comments = c.getJSONObject(TAG_COMMENTS );
- String id = c.getString(TAG_ID);
- String name = c.getString(TAG_NAME);
- String content = c.getString(TAG_CONTENT);
- // 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_CONTENT, content);
- // adding contact to contact list
- queryList.add(contact);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- return null;
- }
- @Override
- protected void onPostExecute(Void result) {
- super.onPostExecute(result);
- // Dismiss the progress dialog
- if (pDialog.isShowing())
- pDialog.dismiss();
- /**
- * Updating parsed JSON data into ListView
- * */
- ListAdapter adapter = new SimpleAdapter(CommentActivityWp.this,
- queryList, R.layout.list_itemwpcmts, new String[] { TAG_NAME, TAG_CONTENT }, new int[] {R.id.name, R.id.content });
- setListAdapter(adapter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement