Android: if elseif popup dialog - android

else if in my codes. Basically i have several condition to fulfill before i can start drawing circles. However upon execution of the program, the popup dialog appears several times even if the condition is met. I would only want a dialog to appear once if there is a message to display. Am i doing it the right way? PLease advice.
my codes are as follows:
if (MainActivity.isClicked() == true) {
if (condition 1) {
canvas.drawCircle(x, y, radius, redPaint);
invalidate();
} else if (condition 2) {
canvas.drawCircle(x, y, radius, bluePaint);
invalidate();
} else if (condition 3){
msg = "green not available";
} else {
msg =" please add more colors";
}
AlertDialog.Builder builder = new Builder(getContext());
builder.setTitle("Warning").setMessage(msg);
builder.setPositiveButton("Okay",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di,int i) {
}
});
builder.create().show();
}// if

Create an method for showing alert when condition meet as:
private void showAlert(String str_mesg){
AlertDialog.Builder builder = new Builder(getContext());
builder.setTitle("Warning").setMessage(str_mesg);
builder.setPositiveButton("Okay",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di,int i) {
}
});
}
Call showAlert in if-else ladder to show alert:
......
} else if (condition 3){
msg = "green not available";
showAlert(msg);
} else {
msg =" please add more colors";
showAlert(msg);
}
.....

Related

Do you know a better way to write this method?

I created this method to handle 2 different way of creating alert dialog, depending on internet status. Do you know a better way to get the same result? Using .equals() on strings in if-else block do not seem a best-practices way... Am i right?
public void noInternetAlertDialog(String errorMsg) {
String title = null;
String msg = null;
if (errorMsg.equals("none")) {
title = "Connection failded";
msg = "Please check internet connection";
} else if (errorMsg.equals("slow")) {
title = "Connection timeout";
msg = "Connection is slow";
}
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(Main.this);
builder.setCancelable(false);
builder.setTitle(title);
builder.setMessage(msg);
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
downloadDialog();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
Use strings.xml for your strings to allow localization (Retry, Cancel, "Connection failded", "Please check internet connection", "Connection timeout", "Connection is slow")
If your values represent something create a data type for them. I mean: if your string will report if internet is available or slow, why keep it as String? A String can be everything and convert to something which says directly what values it can assume will improve your code a lot.
public enum InternetStatus {
Offline,
Slow
}
And a == will be faster than a equals call.
If you don't want to use the enum, consider using "none".equals(errorMessage)
String title = "Connection failded";
String msg = "Please check internet connection";
if ("slow".equals(errorMsg)) {
title = "Connection timeout";
msg = "Connection is slow";
}
You can chain calls to the builder and remove the variable dialog because you can call show() directly (If you still need the reference to the AlertDialog, show() still returns it).
You can go with your fantasy and do something like this
.setTitle(errorMsg == InternetStatus.Slow ? "Connection timeout" : "Please check internet connection")
.setMessage(errorMsg == InternetStatus.Slow ? "Connection failded" : "Connection is slow")
but it will make your code a mess if you want to add more InternetStatus.
You could create a method inside InternetStatus which returns the message (if it will be needed in other places too). But it highly depends on the project you are working with. You could an "extension" method which does it for you just where you need it without put it in the enum code (enums can have methods). You should consider every opportunity.
Maybe?
public enum InternetStatus {
Offline,
Slow
}
public void noInternetAlertDialog(InternetStatus errorMsg) {
String title = getString(R.string.internetfailed);
String msg = getString(R.string.checkyourinternet);
if (errorMsg == InternetStatus.Slow) {
title = getString(R.string.connectiontimeout);
msg = getString(R.string.slowinternet);
}
new AlertDialog.Builder(Main.this)
.setCancelable(false)
.setTitle(title)
.setMessage(msg)
.setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
downloadDialog();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
})
.show();
}
It really is not a good idea to identify a state/result with a string! you should use an enum instead.
enum NoInternetResult {
slow, none
}
and then:
public void noInternetAlertDialog(NoInternetResult result) {
String title = "Connection failded";
String msg = "Please check internet connection";
if (result==NoInternetResult.slow) {
title = "Connection timeout";
msg = "Connection is slow";
}
btw. use strings.xml for you strings like "retry" and "Cancel" (http://developer.android.com/guide/topics/resources/string-resource.html)

IF Else Error in Android application

This if-else statement I am using it onClick method of Android code.
if (input == null){
dispError();
}else{
startAct();
}
when value is true or false startAct() gets implemented;
if (input != null){
dispError();
}else{
startAct();
}
when value is true or false dispError() gets implemented;
input is a string.
actual code of my program:
#Override
public void onClick(View view) {
// Launching Display Meaning Activity
meaning = (EditText) findViewById(R.id.editText1);
input = meaning.getText().toString();
if (input == null){
dispError();
}else{
startAct();
}
}
public void startAct(){
Intent intent =new Intent("com.dictionary.khasi_english.DisplayMeaningActivity");
intent.setClass(MainActivity.this, DisplayMeaningActivity.class);
intent.putExtra(MEANING_INPUT, input);
startActivity(intent);
}
public void dispError(){
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("ERROR");
builder.setMessage("Please enter a Word.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
});
}
}
meaning.getText().toString() will never return null. However, it can return "", an empty string. Use the following code to check against that:
if(input.isEmpty()) {
dispError();
else {
startAct();
}
It is because input, as you said, could be 'true' or 'false'. In both cases input is not null. If you want your if-statement works, you should try:
if(input.equals("true")) {
startAct();
else {
dispError();
}
Assuming you are trying to check whether the user put in any text, you should use TextUtils.isEmpty, which checks against both null and empty strings:
if(TextUtils.isEmpty(input)) {
dispError();
} else {
startAct();
}
if input is a string
try to use input.length to check if it is empty
if(input.length==0)
displayerror();
because if input=""then it is not null.
you can use TextUtils.isEmpty()

Android: Toast won't delay on spinner

I want to delay the toast on selected delay times like (15, 30, 60 seconds and no delay) but it won't work. Here's the code:
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if(FirstLoad){
FirstLoad = false;
return;
}
Toast.makeText(parent.getContext(), "You chose " +
parent.getItemAtPosition(pos).toString()+ " to delay", Toast.LENGTH_LONG).show();
Message message = new Message();
Bundle bun = new Bundle();
bun.putString("delay", parent.getItemAtPosition(pos).toString());
message.obj = bun;
if (pos == 0) {
handler.sendMessageDelayed(message, 0);
}
else if (pos == 1) {
handler.sendMessageDelayed(message, 15000);
}
else if (pos == 2) {
handler.sendMessageDelayed(message, 30000);
}
else if (pos == 3) {
handler.sendMessageDelayed(message, 60000);
}
//handler.sendMessageDelayed(message, 15000);
}
public void onNothingSelected(AdapterView<?> parent) {
return;
}
Help Please.
Try this :
final Toast toast = Toast.makeText(parent.getContext(), "You chose "
+ parent.getItemAtPosition(pos).toString() + " to delay",
Toast.LENGTH_LONG);
Runnable showToastRunnable = new Runnable() {
public void run() {
toast.show();
}
};
if (pos == 0) {
handler.postDelayed(showToastRunnable, 0);
} else if (pos == 1) {
handler.postDelayed(showToastRunnable, 15000);
} else if (pos == 2) {
handler.postDelayed(showToastRunnable, 30000);
} else if (pos == 3) {
handler.postDelayed(showToastRunnable, 60000);
}
Edit:
By the way, I want to transfer this to the send button, i want to delay the toast of "Message sent" according to the delay the user chose. How should I implement it?
How are you fetching the delay? Is it something the user enters in an EditText?
In that case you could just get the delay like this :
int delay = Integer.parseInt(delayEditText.getText().toString());
and then use that delay amount to post the runnable to the handler like this :
handler.postDelayed(showToastRunnable, delay);
You can remove your entire if-else block in this case.
for this you can use custom dialog and hide it after a particular time.
class CustomDialog extends Dialog
{
setContentView(R.layout.dialogxml);
txtview=(TextView)findViewById(R.id.txtmsg);
}
Customdialog dialog= CustomDialog.show();
dialog.hide();
Handler hl_DelayedToast = new Handler(); // scope global
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id)
{
if(FirstLoad)
{
FirstLoad = false;
return;
}
//if else logic to check the time
// if 0
hl_DelayedToast.postDelayed(mytoastshower,0);
// if 1
hl_DelayedToast.postDelayed(mytoastshower,1000);
}
public Runnable mytoastshower = new Runnable
{
public void run()
{
Toast.show();// show the toast
}
}
hope it helps.
Declare your handler this way:
Hanlder handlder=new Handler() {
public void handleMessage (Message msg) {
Toast.makeText(YOUR_ACTIVITY_CLASS_NAME.this,"You chose"+(Bundle(msg.obj)).getString("delay","DEFAULT_VALUE")+"to delay",Toast.LENGTH_LONG).show();
}
};
Simply, you don't have to use a bundle, but you can call msg.what=THE DELEY TIME.
Also, you can call handler.obtainMessage to get a message. See http://developer.android.com/reference/android/os/Handler.html#obtainMessage%28%29
So every time you send a message, it will be handled here, and thus you call show the toast.
Sorry that I don't have Eclipse installed on this laptop, so I can not test the code. However, I believe it works.

Trying to lock screen rotation when displaying dialogs

I am trying to lock my screen in whatever orientation the user is in when the application launches a dialog and then unlocking it when the dialog dismisses. Here is my lock and unlock code:
// Sets screen rotation as fixed to current rotation setting
private void mLockScreenRotation() {
Log.d("####################", "screen orientation is " + mContext.getResources().getConfiguration().orientation);
// Stop the screen orientation changing during an event
if (mContext.getResources().getConfiguration().orientation == 1)
((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
else ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// switch (mContext.getResources().getConfiguration().orientation)
// {
// case Configuration.ORIENTATION_PORTRAIT:
// ((Activity) mContext).setRequestedOrientation(
// ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// break;
// case Configuration.ORIENTATION_LANDSCAPE:
// ((Activity) mContext).setRequestedOrientation(
// ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// break;
// }
}
// allow screen rotations again
private void mUnLockScreenRotation() {
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
mIsScreenRotationLocked = false;
}
I call mLockScreenRotation() when I launch any dialogs and I call mUnlockScreenRotation() in my handler and in my DialogInterface.OnClickListener's.
Sometimes my screen remains locked, but it is not consistent. Any suggestions or ideas why or how to handle this?
Thanks in advance for any help!
Ammendment: code where I am locking my screen:
public void displayProgressDialog(){
mLockScreenRotation();
// Get local handle on class progress dialog for optimization purposes
ProgressDialog temp = mProgressDialog = new ProgressDialog(this);
// Get message string (for some reason this dialog can't handle res IDs for messages)
String message = getString(R.string.downloading);
// Set some paramaters
temp.setIndeterminate(true);
temp.setTitle(R.string.weather_data);
temp.setMessage(message);
temp.setCancelable(false);
temp.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS /*WindowManager.LayoutParams.FLAG_BLUR_BEHIND*/);
temp.show();
}
public void displayLocationSearchDialog(){
mLockScreenRotation();
// Get local handle on class progress dialog for optimization purposes
ProgressDialog temp = mCoordinateSearchDialog = new ProgressDialog(this);
// Get message string (for some reason this dialog can't handle res IDs for messages)
String message = getString(R.string.searching);
// Set some paramaters
temp.setIndeterminate(true);
temp.setTitle(R.string.location_search);
temp.setMessage(message);
temp.setCancelable(false);
temp.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
temp.show();
}
public void showDatafeedFailedDialog(){
mLockScreenRotation();
new AlertDialog.Builder(this)
.setTitle(R.string.network_error)
.setMessage(R.string.weather_data_failed)
.setPositiveButton(R.string.try_again, mTryAgainListener)
.setNegativeButton(R.string.dismiss, null)
.create()
.show();
}
public void showCoordinateSearchFailedDialog(){
mLockScreenRotation();
new AlertDialog.Builder(this)
.setTitle(R.string.network_error)
.setMessage(R.string.location_search_failed)
.setPositiveButton(R.string.try_again, mCoordTryAgainListener)
.setNegativeButton(R.string.dismiss, null)
.create()
.show();
}
private void showGpsAlertDialog(){
mLockScreenRotation();
new AlertDialog.Builder(this)
.setTitle(R.string.gps_error)
.setMessage(R.string.gps_error_details)
.setNeutralButton(R.string.dismiss, null)
.setPositiveButton(R.string.go_to_settings, mToSettingsListener)
.create()
.show();
}
private void showGpsSearchingDialog(){
mLockScreenRotation();
ProgressDialog temp = mGpsSearchAlertDialog = new ProgressDialog(this);
String message = getString(R.string.location_services_details);
String btnText = getString(R.string.cancel);
temp.setIndeterminate(true);
temp.setTitle(R.string.location_services);
temp.setMessage(message);
temp.setButton(btnText, mCancelGpsSearchListener);
temp.setCancelable(true);
temp.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
temp.show();
}
private void showGpsTimeoutAlertDialog(){
mLockScreenRotation();
new AlertDialog.Builder(this)
.setTitle(R.string.gps_error)
.setMessage(R.string.gps_timeout_message)
.setPositiveButton(R.string.try_again, mGpsTimeoutListener)
.setNegativeButton(R.string.dismiss, mGpsTimeoutListener) // check this line with free if still no good
.create()
.show();
}
private void showWeatherAlertDialog(){
Log.d("############", "weather alert dialog");
mLockScreenRotation();
String message = null;
if(mWD.getWarningTypes() == null) return;
int cnt = 0;
int size = mWD.getWarningTypes().size() - 1;
for(String warningType : mWD.getWarningTypes()){
if(cnt == 0) message = warningType;
else if(cnt == size) message += " and " + warningType;
else message += ", " + warningType;
cnt++;
}
new AlertDialog.Builder(this)
.setTitle(R.string.watches_and_warnings)
.setMessage(message)
.setPositiveButton(R.string.go_to_accuweather, mToAlertWebListener)
.setNeutralButton(R.string.dismiss, null)
.create()
.show();
}
private void showNeedLocationAlertDialog() {
mLockScreenRotation();
new AlertDialog.Builder(this).setTitle(R.string.error).setMessage(
R.string.add_location).setNeutralButton(R.string.dismiss, null)
.setPositiveButton(R.string.okay, mToLocationSearchListener)
.create().show();
}
private void showConnectivityAlertDialog() {
mLockScreenRotation();
new AlertDialog.Builder(this).setTitle(R.string.network_error)
.setMessage(R.string.no_connection).setNeutralButton(
R.string.dismiss, null).create().show();
}
private void showCurrentUrlInBrowser(){
// Show current conditions web page
if(mWD.getURL() == null || mWD.getURL().length()
This is a bad solution, but it works. Tested on LG GT540(Android 2.3.7) and Asus Transformer(Android 3.2):
private void stopRotate()
{
if(getResources().getConfiguration().orientation == 1)
{
if( display.getOrientation() == 1 || display.getOrientation() == 2)
setRequestedOrientation(9);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else
{
if( display.getOrientation() == 2 || display.getOrientation() == 3)
setRequestedOrientation(8);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
private void startRotate()
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
Instead of putting the call to change orientation within the dialog (and then presumably dismissing said dialog immediately afterwards), try implementing onDismiss listener to your Dialog, as outlined here.

"Busy" progress dialog causes strange code processing

Let me sum up the situation for you:
I have a button (btnChooseEp), and when you press it an AlertDialog appears.
When something is picked in the AlertDialog, three if statements must be evaluated.
While they are being evaluated, a ProgressDialog appears. It indicates that the app is "busy".
After the evaluation of these statements, the ProgressDialog must disappear.
My problem is described beneath the code.
The entire code block is shown here:
ProgressDialog getTracklistProgressDialog = null;
...
Button btnChooseEp = (Button)findViewById(R.id.btnChooseEp);
btnChooseEp.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
final AlertDialog.Builder builder = new AlertDialog.Builder(GA.this);
builder.setTitle(getText(R.string.chooseEpisode));
builder.setItems(episodes, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, final int pos)
{
getTracklistProgressDialog = ProgressDialog.show(GA.this, "Please wait...",
"Retrieving tracklist...", true);
new Thread()
{
public void run()
{
try
{
String str1, epURL;
if(pos < 9)
{
str1 = getResources().getString(R.string.epNo1);
epURL = String.format(str1, pos+1);
setTracklist(epURL, tracklist);
}
else if(pos < 100)
{
str1 = getResources().getString(R.string.epNo2);
epURL = String.format(str1, pos+1);
setTracklist(epURL, tracklist);
}
else if(pos >= 100)
{
str1 = getResources().getString(R.string.epNo3);
epURL = String.format(str1, pos+1);
setTracklist(epURL, tracklist);
}
}
catch(Exception e)
{}
// Remove progress dialog
getTracklistProgressDialog.dismiss();
}
}.start();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
Not sure if needed, but here is the code for the function setTracklist:
public void setTracklist(String string, TextView tv)
{
try
{
tv.setText(getStringFromUrl(string));
}
catch(Exception e)
{
e.printStackTrace();
}
}
And the code for the function getStringFromUrl can be seen here: http://pastebin.com/xYt3FwaS
Now, the problem:
Back when I didn't implement the ProgressDialog thing (which I have from here, btw: http://www.anddev.org/tinytut_-_displaying_a_simple_progressdialog-t250.html), it worked fine - the setTracklist function retrieves a string from a text file on the internet, and sets the text to a TextView. Now, when I have added the ProgressDialog code, and put the original code into the try statement, only a very little part of the text file is added to the TextView - approximately 22-24 characters, not more. The "busy" ProgressDialog shows up just fine. It worked perfectly before; it was more than capable of loading more than 1300 characters into the TextView.
I don't know if it has anything to do with the thread - I have Googled a lot and found no answer.
So, how do I get it to load in all data instead of just a small part?
(By the way, I would love to be able to set the line "setTracklist(epURL, tracklist);" beneath all of the if statements, but then it says it can't resolve "epURL". Seems stupid to write the same line 3 times!)
Updated 25/1 with current code:
final Handler uiHandler = new Handler();
final Button btnChooseEp = (Button)findViewById(R.id.btnChooseEp);
btnChooseEp.setEnabled(false);
btnChooseEp.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
builder.setTitle(getText(R.string.chooseEpisode));
builder.setItems(episodes2, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, final int pos)
{
replay.setVisibility(View.VISIBLE);
replayWeb.setVisibility(View.VISIBLE);
getTracklistProgressDialog = ProgressDialog.show(GA.this, "Please wait...",
"Retrieving tracklist...", true);
new Thread()
{
public void run()
{
try
{
String str1, epURL;
if(pos < 9)
{
str1 = getResources().getString(R.string.gaEpNo1);
epURL = String.format(str1, pos+1);
setTracklist2(epURL, tracklist);
}
else if(pos < 100)
{
str1 = getResources().getString(R.string.gaEpNo2);
epURL = String.format(str1, pos+1);
setTracklist2(epURL, tracklist);
}
else if(pos >= 100)
{
str1 = getResources().getString(R.string.gaEpNo3);
epURL = String.format(str1, pos+1);
setTracklist2(epURL, tracklist);
}
}
catch(Exception e)
{}
// Remove progress dialog
uiHandler.post(new Runnable()
{
public void run()
{
getTracklistProgressDialog.dismiss();
}
}
);
}
}.start();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
public void setTracklist2(final String string, final TextView tv)
{
try
{
uiHandler.post(
new Runnable()
{
public void run()
{
try
{
tv.setText(getStringFromUrl(string));
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
Notes: "replay" and "replayWeb" are just two TextView's. "btnChooseEp" is enabled when another button is pressed.
My guess is that you are getting bizarre behavior because you are invoking a ui method on a non-ui thread.
getTracklistProgressDialog.dismiss();
must be executed on a ui thread. My guess is that it is crashing and your thread is crashing then leaving some of your resources in a bad state. This would explain why you get a varying amount of characters.
I would try creating a final Handler in your onCreate method which would get bound to the uiThread. In that thread, you can then call
uiHandler.post(
new Runnable() {
public void run(){
getTracklistPRogressDialog.dismiss();
}
}
);
This is quick, so it may not be syntactically correct, check your ide.
This is the best i can get from what you've posted. If you post more of the code I can try to run it to give you more help.
Update:
I think I found your problem:
The idea of having another thread is to do the long running work there, but what we have right now actually does the long running work on the ui thread, the opposite of our goal. What we need to do is move the call to getStringFromUrl(url) from the setTracklist call up into the thread. I would rewrite setTracklist as follows:
public void setTracklist(String tracklistContent, TextView tv)
{
try
{
runOnUiThread(
new Runnable() {
public void run() {
tv.setText(tracklistContent);
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
Then in your inner onClick method, do this:
public void onClick(DialogInterface dialog, final int pos)
{
getTracklistProgressDialog = ProgressDialog.show(GA.this, "Please wait...",
"Retrieving tracklist...", true);
new Thread()
{
public void run()
{
try
{
String str1, epURL;
if(pos < 9)
{
str1 = getResources().getString(R.string.epNo1);
epURL = String.format(str1, pos+1);
String tlContent = getStringFromUrl(epUrl);
setTracklist(epURL, tracklist);
}
else if(pos < 100)
{
str1 = getResources().getString(R.string.epNo2);
epURL = String.format(str1, pos+1);
String tlContent = getStringFromUrl(epUrl);
setTracklist(epURL, tracklist);
}
else if(pos >= 100)
{
str1 = getResources().getString(R.string.epNo3);
epURL = String.format(str1, pos+1);
String tlContent = getStringFromUrl(epUrl);
setTracklist(epURL, tracklist);
}
}
catch(Exception e)
{}
// Remove progress dialog
getTracklistProgressDialog.dismiss();
}
}.start();
}
I'm so, we make the call to the web service/url before we regain ui thread execution. The long running internet retrieval runs on the bg thread and then the ui update happens on the ui thread. Think this should help.

Categories

Resources