im using the azure mobile service. I have some users in the db i want to authenticate, and in order to do that, I execute a query to get a User after you enter a username and a password and press OK. When OK is pressed, if all it's well an intent should be started. How can I display a ProgressDialog until the callback method of the executed query is completed?
EDIT: the problem is that i have a button(logIn button) and when you click it, it will build a query and execute it in an async task, hence my problem. If i just add a progress dialog the call flow will move on since from the onClickListener point of view, the action has finished.
Just show() it before you call the query and dismiss() it in the callback method.
As your using the AsyncTask to query the data , use the onPreExecute and onPostExecute methods to show/dismiss the ProgressDialog.
Create a class which extends the AsyncTask , like this . In the onPreExecute show the ProgressDialog and when your done with fetching the data in doInBackground , in onPostExecute dismiss the dialog
public class QueryTask extends AsyncTask<Void,Void,Object> {
private ProgressDialog progressDialog = null;
private final Context mContext;
public QueryTask(Context context) {
mContext = context;
}
#Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(mContext);
progressDialog.show();
}
#Override
protected Void doInBackground(Void... params) {
// do your stuff to query the data
return null;
}
#Override
protected void onPostExecute(Object result) {
progressDialog.dismiss();
// do your other stuff with the queried result
}
#Override
protected void onCancelled(Object result) {
progressDialog.dismiss();
}
}
Finally, when button onClick execute the task
new QueryTask(YourActivity.this).execute();
This example code was used by me to load all the events from an SQL database. Until the app gets the data from the server, a progress dialog is displayed to the user.
class LoadAllEvents extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Just a moment...");
pDialog.setIndeterminate(true);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_events,
"GET", params);
try {
// Checking for SUCCESS TAG
int success = json.getInt(CONNECTION_STATUS);
if (success == 1) {
// products found
// Getting Array of Products
Events = json.getJSONArray(TABLE_EVENT);
// looping through All Contacts
for (int i = 0; i < Events.length(); i++) {
JSONObject evt = Events.getJSONObject(i);
// Storing each json item in variable
id = evt.getString(pid);
group = evt.getString(COL_GROUP);
name = evt.getString(COL_NAME);
desc = evt.getString(COL_DESC);
date = evt.getString(COL_DATE);
time = evt.getString(COL_TIME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(pid, id);
map.put(COL_GROUP, group);
map.put(COL_NAME, name);
map.put(COL_DESC, desc);
map.put(COL_DATE, date);
map.put(COL_TIME, time);
// adding HashList to ArrayList
eventsList.add(map);
}
} else {
// Options are not available or server is down.
// Dismiss the loading dialog and display an alert
// onPostExecute
pDialog.dismiss();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
getActivity().runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(getActivity(),
eventsList, R.layout.list_item, new String[] {
pid, COL_GROUP, COL_NAME, COL_DATE, COL_TIME },
new int[] { R.id.pid, R.id.group, R.id.name, R.id.header,
R.id.title2 });
setListAdapter(adapter);
}
});
}
hope this helps.
Related
Here in my previous question How to Print Message when Json Response has no fileds? Toast is working fine but if my response is showing no fileds with array and what if I want to use textview instead of Toast? can anyone help me?
public class MessageSent extends ListActivity{
private ProgressDialog pDialog;
JSONArray msg=null;
private TextView nomsg;
private ListView listview;
private ArrayList<HashMap<String,String>> aList;
private static String MESSAGE_URL = "";
private static final String MESSAGE_ALL="msg";
private static final String MESSAGEUSER_ID="msg_user_id";
private static final String MESSAGE_NAME="name";
private static final String MESSAGE_PROFILE="profile_id";
private static final String MESSAGE_IMAGE="image";
private static final String MESSAGE_CAST="cast";
private static final String MESSAGE_AGE="age";
private static final String MESSAGE_LOCATION="location";
private CustomAdapterMessage adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view_msgsent);
nomsg=(TextView)findViewById(R.id.no_message);
String strtexts = getIntent().getStringExtra("id");
System.out.println("<<<<<<<< id : " + strtexts);
MESSAGE_URL = "xxxxx"+strtexts;
// listview=(ListView)findViewById(R.id.list);
//ListView listview = this.getListView();
ListView listview = (ListView)findViewById(android.R.id.list);
new LoadAlbums().execute();
}
});
}
class LoadAlbums extends AsyncTask>> {
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MessageSent.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected ArrayList<HashMap<String,String>> doInBackground(String... args) {
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
ArrayList<HashMap<String,String>> data = new ArrayList<HashMap<String, String>>();
String jsonStr = sh.makeServiceCall(MESSAGE_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null)
{
try
{
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
msg = jsonObj.getJSONArray(MESSAGE_ALL);
// looping through All Contacts
for (int i = 0; i < msg.length(); i++)
{
JSONObject c = msg.getJSONObject(i);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(MESSAGEUSER_ID ,c.getString(MESSAGEUSER_ID));
map.put(MESSAGE_NAME,c.getString(MESSAGE_NAME));
map.put(MESSAGE_PROFILE, c.getString(MESSAGE_PROFILE));
map.put(MESSAGE_IMAGE, c.getString(MESSAGE_IMAGE));
map.put(MESSAGE_CAST, c.getString(MESSAGE_CAST));
map.put(MESSAGE_AGE, c.getString(MESSAGE_AGE)+" years");
map.put(MESSAGE_LOCATION, c.getString(MESSAGE_LOCATION));
// adding HashList to ArrayList
data.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return data;
}
protected void onPostExecute(ArrayList<HashMap<String,String>> result) {
super.onPostExecute(result);
// dismiss the dialog after getting all albums
if (pDialog.isShowing())
pDialog.dismiss();
if(msg == null || msg.length() == 0) {
//Toast.makeText(getApplicationContext(), "No response", Toast.LENGTH_LONG).show
nomsg.setText("No Message Found");
//nomsg.setBackgroundDrawable(R.drawable.borders);
}
if(aList == null) {
aList = new ArrayList<HashMap<String, String>>();
aList.addAll(result);
adapter = new CustomAdapterMessage(getBaseContext(), result);
setListAdapter(adapter);
} else {
aList.addAll(result);
adapter.notifyDataSetChanged();
}
}
}
}
As it seems you have confusions in setting up the app. Let me explain few things and also provide you some sample code.
The use of an AsynTask?
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
But there are some operations that you would have to do in the UI while working in the background thread. In that case you make use of the,
1. onPreExecute(), invoked on the UI thread before the task is executed. This step is normally used to setup the task, for instance by showing a progress bar in the user interface.
2. onPostExecute(Result), invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.
In your specific case as you want to set the values after the operation you have to make use of the latter mathod of the AsynTask.
The same code referring to the example you follow,
//MainActivity.java
public class MainActivity extends ListActivity {
TextView yourTextView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
.
.
//change the ID in this line from what you are using
yourTextView = (TextView) findViewByID(R.id.id_in_activity_main);
.
.
// Calling async task to get json
new GetContacts().execute();
}
/**
* Async task class to get json by making HTTP call
* */
private class GetContacts extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
.
.
}
#Override
protected Void doInBackground(Void... arg0) {
.
.
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
if(contacts == null || contacts.length() <= 0){
yourTextView.setText("No Data");
}
}
}
}
Try this way :
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
if(contacts == null || contacts.length() <= 0){
yourTextView.setText("No Data");
}
}
I am new to android development.I have done some android application to cummounicate with webservice and get data from it into local database in android device.I used AsyncTask<,,> Method to transfer data from internet.
Then I used ProgressDialog to indecate the data transfering.What i am doing.checking how meny tables have to sync and getting all data with for loop and through the for loop call my AsyncTask().execute() Method. (code shows bellow)
Issue is when showing the progress dialog loop length is grater than 1 open several progress dialogs on top itselft and they are not close.But already i called close event
DataTransfering Method
private class NetworkTransfer extends AsyncTask<DataLocation, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LocationFinder.this); // show ProgressDialog
pDialog.setMessage("Processing...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(DataLocation... arg0) {
NetworkUtil networkUtil = new NetworkUtil(); //my http connection class
DataLocation loc = arg0[0];
networkUtil.InsertDataEmp(loc.getC_device_modle(),
loc.getC_usercd(), loc.getC_brach());
DataSource dsx = new DataSource(getApplicationContext());
dsx.updateLocDt(loc.getC_brach()); // send data to webserver
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss(); // for dissmiss the ProgressDialog
}
Function to run execure() method in Button Click Event shows bellow.
public void sendAllUnSyncData() {
DataSource ds = new DataSource(getApplicationContext());
final List<DataLocation> data = ds.GetLocList();
for (int i = 0; i < data.size(); i++) {
final NetworkTransfer networkObject = new NetworkTransfer();
networkObject .execute(data.get(i)); // call AsyncTask Method
}
}
When Running this code if loop length is bigger than (i>1)one (1) Progress Dioalog not closed.But if it's equals to one (1) , (i==1)it's worked!
Also I was tryied with Thread,but result was same.
In your onPreExecute, try to add this:
protected void onPreExecute() {
super.onPreExecute();
if (pDialog == null || !pDialog.isShowing()){
pDialog = new ProgressDialog(LocationFinder.this); // show ProgressDialog
pDialog.setMessage("Processing...");
pDialog.setCancelable(false);
pDialog.show();
}
}
Then set 2 global variables: int dataSized and int dataDone=0.
Initiate dataSized in your sendAllUnSyncData like this:
public void sendAllUnSyncData() {
DataSource ds = new DataSource(getApplicationContext());
final List<DataLocation> data = ds.GetLocList();
dataSized=data.size();
for (int i = 0; i < data.size(); i++) {
final NetworkTransfer networkObject = new NetworkTransfer();
networkObject .execute(data.get(i)); // call AsyncTask Method
}
}
Then on your onPostExecute, do this:
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
dataDone++;
if(dataDone==dataSized){
if (pDialog.isShowing())
pDialog.dismiss(); // for dissmiss the ProgressDialog
}
}
Let me know if it's working.
I have the following AsyncTask in a Fragment and would like to clear the listview and repopulate it when a button is clicked. Here is what I have tried:
The button click:
btnRefresh.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
lv.setAdapter(null);
new LoadAllProducts().execute();
}
});
And here is my AsyncTask:
class LoadAllProducts extends AsyncTask<String, String, String> {
//ListView lv = (ListView) rootView.findViewById(R.id.list);
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
lv.setAdapter(null);
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Loading your trips. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_trips, "GET", params);
// Check your log cat for JSON response
Log.d("All Trips: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
trips = json.getJSONArray(TAG_TRIPS);
// looping through All Products
for (int i = 0; i < trips.length(); i++) {
JSONObject c = trips.getJSONObject(i);
// Storing each json item in variable
String tripid = c.getString(TAG_TRIPID);
String tripname = c.getString(TAG_TRIPNAME);
String userId = c.getString("uid");
// creating new HashMap
DatabaseHandler_Helpers db = new DatabaseHandler_Helpers(getActivity());
HashMap<String, String> map = new HashMap<String, String>();
if (userId.equals(db.getUserDetails().get("uid"))) {
// adding each child node to HashMap key => value
map.put(TAG_TRIPID, tripid);
map.put(TAG_TRIPNAME, tripname);
// adding HashList to ArrayList
tripList.add(map);
} //else {
//map.put(TAG_TRIPID, "");
//map.put(TAG_TRIPNAME, "You have no tracked trips.");
//tripList.add(map);
//}
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getActivity(),
NewTrip_Activity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
((Activity) getActivity()).runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
getActivity(), tripList,
R.layout.list_item, new String[] { TAG_TRIPID,
TAG_TRIPNAME, "TEST"},
new int[] { R.id.pid, R.id.name, R.id.mileage });
// updating listview
((ListView) lv.findViewById(R.id.list)).setAdapter(adapter);
}
});
}
}
Problem is that clicking the button clears the listview but then adds twice the items back. So what was already in the listview plus the same items again. If you click the button again, it adds the items a third time!
I know I must be missing something but all I find online is using a ArrayAdapter rather than ListAdapter. Thanks for any help solving this!
You need to Clear the tripList.clear() your tripList(arraylist) before add the map to them tripList.add(map) otherwise it will add to the existing old value
Make adapter global
ListAdapter adapter ;
And change onClick to this
public void onClick(View view) {
new LoadAllProducts().execute();
adapter.notifyDataSetChanged();
}
Also you need to check tripList that its not appending the list before adding items make it clear.
do adpater.clear();
and tripList.clear();
After your AsyncTask is executed you can clear your arraylist
tripList.clear();
adapter.notifyDataSetChanged();
or you can set adapter null also
lv.setAdapter(null);
adapter.notifyDataSetChanged();
You have to declare adapter globally and used its instance to clear data and then fill it again
You have to referesh the Listview after setting null in adapter
btnRefresh.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
lv.setAdapter(null);
adapter.notifyDataSetChanged();
new LoadAllProducts().execute();
}
});
I have an listview that contacts a web service whenever it is called and this is what it looks like
public class ListView extends ListActivity {
ArrayList<HashMap<String, String>> questionList;
final String TAG_DATA_WEB = "data";
private String stringxxx;
ProgressDialog pDialog;
LoadAllData mTask;
JSONArray question = null;
android.widget.ListView lv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.listview);
stringxxx = getIntent().getStringExtra("TAG_SEARCH");
questionList = new ArrayList<HashMap<String, String>>();
mTask = new LoadAllData();
mTask.execute();
}
#Override
protected void onListItemClick(android.widget.ListView l, View v, int pos, long id) {
super.onListItemClick(l, v, pos, id);
HashMap<String, String> item = questionList.get(pos);
Intent i = new Intent(ListView.this, SingleListItem.class);
i.putExtra(TAG_DATA_WEB, item.get(TAG_DATA_WEB));
startActivity(i);
}
#Override
public void onBackPressed()
{
/** If user Pressed BackButton While Running Asynctask
this will close the ASynctask.
*/
if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED)
{
mTask.cancel(true);
}
super.onBackPressed();
Intent i = new Intent(ListView.this, PREV.class);
startActivity(i);
finish();
}
#Override
protected void onDestroy() {
if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED)
{
mTask.cancel(true);
}
super.onDestroy();
}
#Override
protected void onPause() {
if (pDialog != null)
{
if(pDialog.isShowing())
{
pDialog.dismiss();
}
super.onPause();
}
}
class LoadAllData extends AsyncTask<String, Void, JSONObject> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ListView.this);
pDialog.setMessage("Loading Data. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected JSONObject doInBackground(String... args) {
pDialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
public void onCancel(DialogInterface dialog) {
mTask.cancel(true);
Intent i = new Intent(ListView.this, PREV.class);
startActivity(i);
finish();
}
});
JSONObject json = new JSONObject();
try {
String query = URLEncoder.encode(searchTerm, "utf-8");
String URL = "http://example.com";
JSONParsser jParser = new JSONParsser();
json = jParser.readJSONFeed(URL);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return json;
}
#Override
protected void onPostExecute(JSONObject json) {
try {
JSONArray questions = json.getJSONObject("all").getJSONArray("questions");
for(int i = 0; i < DT.length(); i++) {
JSONObject question = DT.getJSONObject(i);
String data = question.getString(TAG_DATA_WEB);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_DATA_WEB, data);
questionList.add(map);
pDialog.dismiss();
ListAdapter adapter = new SimpleAdapter(getBaseContext(), questionList,
R.layout.listelements,
new String[] { TAG_DATA_WEB }, new int[] {
R.id.Subject,});
setListAdapter(adapter);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
The problem I have is that when I click on an item on the listview to go to the next activity, it does as its suppose too with no problem its just when I pressed the back button to go back the listview, the listview activity restarts and it also contacts the web service again to retrieve the information like as if I put finish(); after startArtivity(I); in the onItemClick part of the code. Now normally this wouldn't be a problem if you web service didn't have a search limit but the one i am using does. So basically what Im saying is that when the user clicks on an listview item to go to the next activity and when they press the onBack button, I want the information to still be there instead of the application contacting the web service again to retrieve information and the end result will be the search limit being reached. Can anybody help me with this?
I have used XML parsing so I can probably give you help logically.
You can use bean class with get and set methods and store the results
you get from web service.
Use Set methods to store the values where you have written the
parsing code.
Use get methods in your activity's adapter code to retrieve those
values.
This way web service won't be called again when you reach that
activity using back button.
But remember, if you launch that activity with service again from its parent, web service will be called again.
You would have several options:
Replace the AsyncTask data loading with an AsyncTaskLoader data loading. Check the Loader developer article first. I dropped using AsyncTasks for data loading long time ago...
The scond option is to store the data you receive and don't call the webservice next time. For this, store the data somehow in onSaveInstanceState and in onCreate check if Bundle parameter is not null and if you have data set there for th same key you used in onSaveInstanceState. If true, you already have the data. If false, query.
Depending on data importance and volatility you could save it once in some kind of app persistence (shared preference or sqlite) once you downloaded it and use it every time the activity recreates or creates itself.
In my call to my AsyncTask, new LoadBookBuyInfo().execute();, I receive the error: "LoadBookBuyInfo cannot be resolved to a type". I'm using fragments and I've scoured the internet for an answer but to no avail. Any help would be greatly appreciated, thanks.
Here's my code:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.buy_tbfrag, container, false);
//bookLV = (ListView)view.findViewById(R.id.list);
//bookLV = getListView();
bookLV = (ListView)view.findViewById(android.R.id.list);
//enables filtering for the contents of the given ListView bookLV
bookLV.setTextFilterEnabled(true);
//Search inputed book title
titleSearch = (EditText)view.findViewById(R.id.titleSearch);
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState){
System.out.println("onActivityCreated executed");
bookArray = new ArrayList<Bookinfo>();
//**************************************************************************************//
//*******************New Async Task & JSON Parser code starts here**********************//
//**************************************************************************************//
//Load bookArray in Background Thread
new LoadBookBuyInfo().execute();
//Background AsyncTask to load all BookBuyInfo by making Http Request
class LoadBookBuyInfo extends AsyncTask<String, String, String> {
//Show Progress Dialog before starting background thread
#Override
protected void onPreExecute() {
super.onPreExecute();
//pDialog = new ProgressDialog(BuyFragTab); //might can only be activity
pDialog = new ProgressDialog(getActivity());//might can only be activity
pDialog.setMessage("Loading Books...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
//Get BookBuyInfo Data
protected String doInBackground(String... arg0) {
//Building parameters
ArrayList<NameValuePair> bookValues = new ArrayList<NameValuePair>();
//getting JSON string from URL
JSONObject json = jsonParser.makeHttpRequest(BOOKBUY_URL, "GET", bookValues);
//Check logcat for JSON response
Log.d("Book Buy JSON: ", json.toString());
//Get JSON Data
try {
bookBuyInfo = json.getJSONArray("books");
//bookArray = new ArrayList<Bookinfo>();
//loop through all books and load data
for (int i = 0; i < bookBuyInfo.length(); i++) {
JSONObject b = bookBuyInfo.getJSONObject(i);
...
(book code setup)}
}
catch (JSONException e) {
e.printStackTrace();
}
return null;
}
//}
//After completing background task, dismiss the progress dialog
protected void onPostExecute(String file_url) { // might need to be (String result) here
//dismiss the dialog after getting all the records
pDialog.dismiss();
//update UI from background thread
//runOnUiThread(new Runnable() {
getActivity().runOnUiThread(new Runnable() {
public void run() {
//updating parsed JSON data into ListView
adapter = new MyCustomAdapter(getActivity(), R.layout.buy_tbfrag, bookArray);
bookLV.setAdapter(adapter);
}
});
}
}
It looks like you placed your AsyncTask class inside onActivityCreated method. Move the whole AsyncTask class outside of this method and then call it from there.