I use Asynctask to load and get data from php. And I have to pass 2 parameters to php.
But I don't know how.
Here is the java code :
public class info extends Activity{
ProgressDialog pDialog;
TextView movie_tittle, studio, date;
int std;
String movie, reservation, ttl, dt;
private String URL_CATEGORIES = "http://10.0.2.2/cinemainfo/info.php";
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> accountsList;
JSONArray accounts = null;
private static final String TAG_SUCCESS = "success";
private static final String TAG_ACCOUNT = "message";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
movie = getIntent().getStringExtra("kode_intent");
reservation = getIntent().getStringExtra("kode_intent2");
movie_tittle=(TextView)findViewById(R.id.tv_tittle);
date=(TextView)findViewById(R.id.tv_date);
studio=(TextView)findViewById(R.id.tv_studio);
new GetCategories().execute();
}
private class GetCategories extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(info.this);
pDialog.setMessage("Please Wait..");
pDialog.setCancelable(false);
pDialog.show();
}
protected Void doInBackground(Void... arg0) {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("id_movie", movie));
params.add(new BasicNameValuePair("id_reservation", reservation));
JSONObject json = jParser.makeHttpRequest(URL_CATEGORIES, "GET", params);
Log.d("All Accounts: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
accounts = json.getJSONArray(TAG_ACCOUNT);
for (int i = 0; i < accounts.length(); i++) {
JSONObject json_data = accounts.getJSONObject(i);
ttl=json_data.getString("movie_tittle");
dt=json_data.getString("date");
std = json_data.getInt("studio");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
result();
}
}
private void result() {
try{
movie_tittle.setText(ttl);
date.setText(dt);
studio.setText(String.valueOf(std));
}
catch(Exception e){
Log.e("log_tag","Error in Display!" + e.toString());;
}
}
}
I want to pass id_movie and id_reservation to php code..Both is getting from movie = getIntent().getStringExtra("kode_intent"); and reservation = getIntent().getStringExtra("kode_intent2");
But when I run the code in emulator, It displays nothing..The php code is fine..But I'm not sure with my java code. How to pass 2 parameters in doInBackground asynctask? Did I do something wrong ?
String curloc = current.toString();
String itemdesc = item.mDescription;
ArrayList<String> passing = new ArrayList<String>();
passing.add(itemdesc);
passing.add(curloc);
new calc_stanica().execute(passing); //no need to pass in result list
And change your async task implementation
public class calc_stanica extends AsyncTask<ArrayList<String>, Void, ArrayList<String>> {
ProgressDialog dialog;
#Override
protected void onPreExecute() {
dialog = new ProgressDialog(baraj_mapa.this);
dialog.setTitle("Calculating...");
dialog.setMessage("Please wait...");
dialog.setIndeterminate(true);
dialog.show();
}
protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> passed = passing[0]; //get passed arraylist
//Some calculations...
return result; //return result
}
protected void onPostExecute(ArrayList<String> result) {
dialog.dismiss();
String minim = result.get(0);
int min = Integer.parseInt(minim);
String glons = result.get(1);
String glats = result.get(2);
double glon = Double.parseDouble(glons);
double glat = Double.parseDouble(glats);
GeoPoint g = new GeoPoint(glon, glat);
String korisni_linii = result.get(3);
}
Calling:
String[] arrayOfValue = new String[2];
arrayOfValue[0] = movie;
arrayOfValue[1] = reservation;
new GetCategories().execute(arrayOfValue);
Usage:
protected ArrayList<String> doInBackground(String... passing){
String movie = passing[0];
String reservation = passing[1];
}
Related
I have 2 asyncTasks. One for GetCheckLists another for GetCheckListItems.
In CheckList class, it has checkListId,Title,etc and arrayList of checkListItems.
First I get all the checkLists using GetCheckListAsyncTask. Now for each checkList I am calling GetCheckListItemsAsync task to get all the checkListItems.
Now onPostExecute method of GetCheckListItemsAsyncTask I want to set the checkListItemArrayList.
How can I make sure to add checkListItemArrayList to checkList item's object?
CheckListActivity:
public class CheckListActivity extends AppCompatActivity implements CheckListAdapter.OnItemClickListener{
private ProgressDialog progressDialog;
private RecyclerView recyclerView;
private ArrayList<CheckList> checkLists = new ArrayList<>();
private CheckList mCheckList;
private ArrayList<CheckListItem> itemList;
private ArrayList<CheckList> checkListArrayList;
private CheckListAdapter mAdapter;
JSONArray checkListsItemArray,checkListArray;
public int iterationCount = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_list);
checkListArrayList = new ArrayList<>();
mEventId = mIntent.getStringExtra("eventId");
mCheckList = new CheckList();
progressDialog = new ProgressDialog(CheckListActivity.this);
recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
mAdapter = new CheckListAdapter(checkListArrayList,CheckListActivity.this,CheckListActivity.this);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
GetCheckListAsyncTask getCheckListAsyncTask = new GetCheckListAsyncTask();
getCheckListAsyncTask.execute(mEventId);
}
}
#Override
public class GetCheckListsItemAsyncTask extends AsyncTask<String, Void, JSONObject> {
private String api;
private JSONObject jsonParams;
public GetCheckListsItemAsyncTask(){}
#Override
protected JSONObject doInBackground(String... params) {
try {
api = getResources().getString(R.string.server_url) + "api/checklist_items/getChecklistItems.php";
jsonParams = new JSONObject();
String checklistId = params[0]; // params[0] is username
jsonParams.put("checklistId", checklistId);
ServerRequest request = new ServerRequest(api, jsonParams);
return request.sendRequest();
} catch(JSONException je) {
return Excpetion2JSON.getJSON(je);
}
} //end of doInBackground
#Override
protected void onPostExecute(JSONObject response) {
super.onPostExecute(response);
Log.e("ServerResponse", response.toString());
try {
int result = response.getInt("result");
String message = response.getString("message");
if (result == 1) {
Toast.makeText(CheckListActivity.this, message, Toast.LENGTH_LONG).show();
//code after getting profile details goes here
checkListsItemArray = response.getJSONArray("checklistItems");
for (int i = 0; i < checkListsItemArray.length(); i++) {
int pendingTasks = 0,completedTasks = 0;
itemList = new ArrayList<>();
CheckListItem checkListItem = new CheckListItem();
JSONObject subObject = checkListsItemArray.getJSONObject(i);
String checkListItemName = subObject.getString("text");//name of the attribute in response
String checkListItemBudget = subObject.getString("budget");//name of the attribute in response
String checkListItemTimedate = subObject.getString("time_due");
String checkListItemReminder = subObject.getString("reminder");
String checkListItemId = subObject.getString("checklistItemId");
String checkListItemStatus = subObject.getString("status");
if (checkListItemStatus.equals("1")) {
completedTasks++;
}
if (checkListItemStatus.equals("0")) {
pendingTasks++;
}
checkListItem.setTitle(checkListItemName);
checkListItem.setBudget(checkListItemBudget);
checkListItem.setDateTime(checkListItemTimedate);
checkListItem.setReminder(checkListItemReminder);
checkListItem.setCheckListItemId(checkListItemId);
checkListItem.setStatus(checkListItemStatus);
checkListItem.setPendingItem(pendingTasks);
checkListItem.setCompletedItem(completedTasks);
itemList.add(checkListItem);//adding string to arraylist
}
if(checkListArrayList.size() < iterationCount) {
iterationCount++;
String checkListId =
checkListArrayList.get(iterationCount).getCheckListId();
CheckList checkList1 = checkListArrayList.get(iterationCount);
checkList1.setCheckListItemArrayList(itemList);
}
mAdapter.notifyDataSetChanged();
}
else {
Toast.makeText(CheckListActivity.this, message, Toast.LENGTH_LONG).show();
//code after failed getting profile details goes here
}
} catch(JSONException je) {
je.printStackTrace();
Toast.makeText(CheckListActivity.this, je.getMessage(), Toast.LENGTH_LONG).show();
}
} //end of onPostExecute
}
public class GetCheckListAsyncTask extends AsyncTask<String, Void, JSONObject> {
private String api;
private JSONObject jsonParams;
public GetCheckListAsyncTask(){}
#Override
protected JSONObject doInBackground(String... params) {
try {
api = getResources().getString(R.string.server_url) + "api/checklist/getChecklists.php";
jsonParams = new JSONObject();
String eventId = params[0]; // params[0] is username
jsonParams.put("eventId", eventId);
ServerRequest request = new ServerRequest(api, jsonParams);
return request.sendRequest();
} catch(JSONException je) {
return Excpetion2JSON.getJSON(je);
}
} //end of doInBackground
#Override
protected void onPostExecute(JSONObject response) {
super.onPostExecute(response);
//Log.e("ServerResponse", response.toString());
try {
int result = response.getInt("result");
String message = response.getString("message");
if (result == 1 ) {
Toast.makeText(CheckListActivity.this, message, Toast.LENGTH_LONG).show();
//code after getting profile details goes here
checkListArray = response.getJSONArray("checklists");
for (int i = 0; i < checkListArray.length(); i++) {
CheckList checkList = new CheckList();
JSONObject subObject = checkListArray.getJSONObject(i);
String checkListName = subObject.getString("checklist");//name of the attribute in response
String checkListBudget = subObject.getString("budget");//name of the attribute in response
String checkListIcon = subObject.getString("icon");
String checkListId = subObject.getString("checklistId");
checkList.setCheckListTitle(checkListName);
checkList.setBudget(checkListBudget);
checkList.setImageIcon(checkListIcon);
checkList.setCheckListId(checkListId);
checkListArrayList.add(checkList);
iterationCount++;
new GetCheckListsItemAsyncTask().execute(checkListId);
mAdapter.notifyDataSetChanged();
}
if ((progressDialog != null) && progressDialog.isShowing()) {
progressDialog.dismiss();
}
} else {
Toast.makeText(CheckListActivity.this, message, Toast.LENGTH_LONG).show();
//code after failed getting profile details goes here
if ((progressDialog != null) && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
} catch(JSONException je) {
je.printStackTrace();
Toast.makeText(CheckListActivity.this, je.getMessage(), Toast.LENGTH_LONG).show();
}
} //end of onPostExecute
#Override
protected void onPreExecute(){
super.onPreExecute();
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
}
How to set CheckListItemsArrayList to the objects of checkListArrayList sequence wise? Please help. Thank you..
You need to elaborate your question. It is very confusing.
But I think that you want to add items to your AsyncTask class.
You can use the Constructor Method for this.
GetCheckListAsyncTask getCheckListAsyncTask = new GetCheckListAsyncTask(checkListsItemArray);
getCheckListAsyncTask.execute(mEventId);
And for AsyncTask Just Add:
JSONArray m_checkListsItemArray;
public GetCheckListsItemAsyncTask(JSONArray checkListsItemArray){
m_checkListsItemArray = checkListsItemArray;
//Do something here with checkListsItemArray;
}
And use m_checkListsItemArray anywhere in the AsycTask class.
Each time you start a task, you have no control when it ends. The tasks are running Asynchronously so they won't end in the order you start them. Maybe have a field level Array or ArrayList that adds results each time a task ends and then when everyhthing has ended you can work with the array results.
Could someone help me. I was following a very long tutorial and got to the end and can't fix this error. Starting at public void update list the code below is underlined in red and I can't seem to correct the problem.
public class readComments extends ListActivity {
private ProgressDialog pDialog;
private static final String READ_COMMENTS_URL = "http://120.120.1.100 /webservice/comments.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_TITLE = "title";
private static final String TAG_POSTS = "posts";
private static final String TAG_POST_ID = "post_id";
private static final String TAG_USERNAME = "username";
private static final String TAG_MESSAGE = "message";
private JSONArray mComments = null;
private ArrayList<HashMap<String, String>> mCommentList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.read_comments);
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
//loading the comments via AsyncTask
new LoadComments().execute();
}
public void addComment(View v)
{
Intent i = new Intent(readComments.this, AddComment.class);
startActivity(i);
}
public void updateJSONdata() {
}
private void updateList() {
}
public class LoadComments extends AsyncTask<Void, Void, Boolean> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(readComments.this);
pDialog.setMessage("Loading Comments...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
public void updateJSONdata() {
mCommentList = new ArrayList<HashMap<String, String>>();
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(READ_COMMENTS_URL);
try {
mComments = json.getJSONArray(TAG_POSTS);
for (int i = 0; i < mComments.length(); i++) {
JSONObject c = mComments.getJSONObject(i);
String title = c.getString(TAG_TITLE);
String content = c.getString(TAG_MESSAGE);
String username = c.getString(TAG_USERNAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_TITLE, title);
map.put(TAG_MESSAGE, content);
map.put(TAG_USERNAME, username);
mCommentList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
//Problem starts here everything underlined in red
#Override
private void updateList() {
ListAdapter adapter = new SimpleAdapter(this, mCommentList,
R.layout.single_post, new String[]{TAG_TITLE, TAG_MESSAGE,
TAG_USERNAME}, new int[]{R.id.title, R.id.message,
R.id.username});
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
I have been trying to work on an app in which after clicking ,a new activity opens up and loads the data from the url.
Here is the new activity code
ProgressDialog dialog;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
private class MyTask extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
dialog.setMessage("Processing");
dialog.setIndeterminate(true);
dialog.show();
dialog.getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
super.onPreExecute();
}
#Override
protected Void doInBackground(Void... params) {
try {
JSONObject jsonObject = new JSONObject();
String url = " http://www.trailermag.com/tsappapis/?request=featuredAdList";
JSONArray trailersJSON = jsonObject.getJSONArray(url);
for (int i = 0; i < trailersJSON.length(); i++) {
Trail aTrail = new Trail();
JSONObject contactObject = trailersJSON.getJSONObject(i);
aTrail.id = contactObject.getString(V_Id);
aTrail.image = contactObject.getString(V_Image);
aTrail.title = contactObject.getString(V_Title);
aTrail.price = contactObject.getString(V_Price);
webData.add(aTrail);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (dialog.isShowing()) {
System.out.println("IN POST EXE");
dialog.dismiss();
}
}
}
Once try and replace this code with your code this will work and i have tested it.
JSONArray mJsonArray = new JSONArray(response);
for (int i = 0; i < mJsonArray.length(); i++) {
JSONObject mJsonObject = mJsonArray.getJSONObject(i);
String idStr = mJsonObject.getString("id");
String imageStr = mJsonObject.getString("image");
String titleStr = mJsonObject.getString("title");
String priceStr = mJsonObject.getString("price");
}
Happeee...Programming....
I am developing one application in that i have to receive data from server ,I am successfully read data . here i have problem i receive data from server code wrote in AsyncTask,and send data from AsyncTask to My activity,here i send only one data out of three,my json object have 3 objects.i can get 3 objects in AsyncTask but not getting in Activity
my AsyncTask
public class ReceivingLatLongAsync extends AsyncTask<Void, Void, Void> {
private ProgressDialog pDialog;
Context mContext;
JSONArray jsonArryDetails=null;
public static final String DETAILS = "locations";
public static final String LAT = "lat";
public static final String LNG = "lng";
public static final String ADDRESS = "address";
public static final String CTIME = "ctime";
private String lat1;
private String lng1;
private String address1;
private String time1;
public ReceivingLatLongAsync(Context context){
this.mContext = context;
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(mContext);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
ServiceHandler serviceHandler= new ServiceHandler();
String jSonString = `serviceHandler.makeServiceCall
(TrafficConstants.RECIEVE_LATLON_POL_URL, ServiceHandler.POST);`
Log.e("Response: ", "> " + jSonString);
if(jSonString != null){
try {
JSONObject jsonObject = new JSONObject(jSonString);
jsonArryDetails = jsonObject.getJSONArray(DETAILS);
for(int i = 0;i<jsonArryDetails.length();i++){
JSONObject mapDetails =
jsonArryDetails.getJSONObject(0);
lat1 = mapDetails.getString(LAT);
lng1 = mapDetails.getString(LNG);
address1 = mapDetails.getString(ADDRESS);
time1 = mapDetails.getString(CTIME);
Log.e("ADDRESS1", address1);
Log.e("TIME2",time1);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pDialog.dismiss();
Intent intent = new Intent(mContext,GetLatLongForTPActivity.class);
intent.putExtra("LAT", lat1);
intent.putExtra("LNG", lng1);
intent.putExtra("ADDRESS", address1);
intent.putExtra("time",time1);
mContext.startActivity(intent);
}
}
my activty
public class GetLatLongForTPActivity extends FragmentActivity
implements LocationListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_lat_long_for_tp);
timeEdit = (EditText)findViewById(R.id.timeId);
submitBtn = (Button)findViewById(R.id.subId);
Intent intent = getIntent();
String anotherLAT=intent.getStringExtra("LAT");
String anotherLNG=intent.getStringExtra("LNG");
Log.e(" NEW LATLONG",anotherLAT);
}
Becouse it is an jsonArray and now you send only the last object not the entier array
Change this
JSONObject mapDetails =
jsonArryDetails.getJSONObject(0);
to
JSONObject mapDetails =
jsonArryDetails.getJSONObject(i);
You have to add something like
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
for(int i = 0;i<jsonArryDetails.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject mapDetails =
jsonArryDetails.getJSONObject(i);
lat1 = mapDetails.getString(LAT);
lng1 = mapDetails.getString(LNG);
address1 = mapDetails.getString(ADDRESS);
time1 = mapDetails.getString(CTIME);
map.put(LAT, lat1);
map.put(LNG, lg1);
map.put(ADDRESS, address1 );
map.put(CTIME, time1 );
mylist.add(map);
}
In for loop change the index :
for(int i = 0;i<jsonArryDetails.length();i++){
JSONObject mapDetails =jsonArryDetails.getJSONObject(i);
//etc ^ //change here
You need to create a class that stores the four fields you are using (lat,long,address,time), make that object parable, you could use this example: http://aryo.lecture.ub.ac.id/android-passing-arraylist-of-object-within-an-intent/ ;
And after that you can attach the array to the intent using:
intent.putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)
This would be the correct way to handle this, even if it's a little more complicated then you originally would have hoped.
I want to display a loading process when my application is loading data from the database.
This is my Java file.
Where do I have to put the function to display the loading process?
public class AksesServerActivity extends ListActivity {
private static String link_url = "http://plnskh.zz.mu/android/berita/cekdaftar.php";
private static final String AR_ID = "id";
private static final String AR_JUDUL = "judul";
private static final String AR_CONTENT = "content";
JSONArray artikel = null;
ArrayList<HashMap<String, String>> daftar_artikel = new ArrayList<HashMap<String, String>>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
JSONParser jParser = new JSONParser();
JSONObject json = jParser.AmbilJson(link_url);
try {
artikel = json.getJSONArray("artikel");
for(int i = 0; i < artikel.length(); i++){
JSONObject ar = artikel.getJSONObject(i);
String id = ar.getString(AR_ID);
String judul = ar.getString(AR_JUDUL);
String content = ar.getString(AR_CONTENT).substring(0,100)+"...(baca selengkapnya)";
HashMap<String, String> map = new HashMap<String, String>();
map.put(AR_ID, id);
map.put(AR_JUDUL, judul);
map.put(AR_CONTENT, content);
daftar_artikel.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
this.adapter_listview();
}
public void adapter_listview() {
ListAdapter adapter = new SimpleAdapter(this, daftar_artikel,
R.layout.list_item,
new String[] { AR_JUDUL, AR_CONTENT, AR_ID}, new int[] {
R.id.judul, R.id.content, R.id.kode});
setListAdapter(adapter);
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
String kode = ((TextView) view.findViewById(R.id.kode)).getText().toString();
Intent in = new Intent(AksesServerActivity.this, DetailAksesServer.class);
in.putExtra(AR_ID, kode);
startActivity(in);
}
});
}
}
public class LongOperation extends AsyncTask<String, String, String>
{
ProgressDialog pdialog;
#Override
protected String doInBackground(String... params) {
JSONParser jParser = new JSONParser();
JSONObject json = jParser.AmbilJson(link_url);
try {
artikel = json.getJSONArray("artikel");
for(int i = 0; i < artikel.length(); i++){
JSONObject ar = artikel.getJSONObject(i);
String id = ar.getString(AR_ID);
String judul = ar.getString(AR_JUDUL);
String content = ar.getString(AR_CONTENT).substring(0,100)+"...(baca selengkapnya)";
HashMap<String, String> map = new HashMap<String, String>();
map.put(AR_ID, id);
map.put(AR_JUDUL, judul);
map.put(AR_CONTENT, content);
daftar_artikel.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pdialog.dismiss();
this.adapter_listview();
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pdialog = new ProgressDialog(NewsActivity.this);
pdialog.setMessage("Loading");
pdialog.show();
}
}
for more clarification about asynchronous task and its methods, check here
You must use AsyncTask class, override doInBackground method to perform your databse fetch, onPreExecute method to show your loading and onPostExecute to hide it. you can refer AsynTask process and AsynTask post for more information