I implemented Progress Bar on action bar during network call but displaying the progress Bar on Action Bar is too large. I want to set dynamic size of progressbar. I searched lot but not achieve my goal.so following is the code for ActionBar ProgressBar. Please anybody suggest me some answer and anybody having another way to do above task please tell me.
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); }
protected void onPreExecute() {
// Show IndeterminateProgressBar
setSupportProgressBarIndeterminateVisibility(true); }
protected void onPostExecute(Void result) {
setSupportProgressBarIndeterminateVisibility(false);}
Thanks In Advance
Set a Timer and use LayoutParams to change the size.
{ParentLayout}.LayoutParams params = new {ParentLayout}.LayoutParams(h,w);
progressBar.setLayoutParams(params);
And use the built-in java Timer to time it.
Related
I have an activity that I want to show progress. I'm requesting the window feature before setContentView is called, yet I see no progress showing. Progress works on [0, 10000] according to the documentation. What am I missing?
The action bar appears like a normal action bar without progress, with a solid blue line underneath the title/menu
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarVisibility(true);
setProgress(5000);
super.onCreate(savedInstanceState);
// set content view
}
I already have the
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_profile);
and the
setProgressBarIndeterminateVisibility(true);
if (isOnline()) {
retrieveProfile();
} else {
Toast.makeText(ProfileActivity.this, getString(R.string.internet_error), Toast.LENGTH_LONG).show();
}
setProgressBarIndeterminateVisibility(false);
This code was already working, but somehow the progress bar doesn't show anymore.
Any idea would be appreciated!
That function doesn't show the bar, it just makes it show an indeterminate bar rather than a determinate bar. You still need to call setProgressBarVisibility(true);
Try this...
setSupportProgressBarIndeterminateVisibility(boolean)
to get backward compatibility.
I have two layouts for orientation: portrait layout and landscape layout. In the portrait layout, I used the progress bar and download the files. I used AsyncTask and updated the progress bar in the onPostExecute() method. When I change the landscape orientation, the system will replace with landscape layout. My problem is that when I change the landscape orientation during the downloading files, I got the NullPointerException for progress bar. Because AsyncTask tried to update the progress bar after downloading files. I have two questions for that.
I have no idea how to skip the updating this progress bar.
And when the orientation change back to portrait during downloading, I want to show the progress bar status.
EDIT
#Override
protected void onProgressUpdate(Integer... values) {
int count = values[0];
loadingBar.setProgress(count);
progressTxt.setText(count +"/" + listSize);
}
#Override
protected void onPostExecute(Integer result) {
loadingBar.setVisibility(View.INVISIBLE);
loadingBarLbl.setVisibility(View.INVISIBLE);
}
#Override
protected void onPreExecute() {
loadingBar.setVisibility(View.VISIBLE);
undefinedloadingBarLbl.setVisibility(View.VISIBLE);
}
Thanks.
My problem is that I have complicated layout, and when my application starts, I see how every view is adding to layout. I see my custom window title bar construction too. I see empty custom window title, with gradient background on start, and then 1 - 2 sec later I see completed window title with my views.
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
Is there simple way to show white screen, until my activity and custom title bar will be completely constructed?
The main trouble is that I cant start application with no title, and then add custom window title.
Only solution I know is splash screen, but it is too complicated for just this small task.
Use an asynctask like this:
private class LoadingMyView extends AsyncTask<void, void, int> {
protected void onPreExecute ()
{
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
//show whiteView
}
protected int doInBackground() {
return 0;
}
protected void onPostExecute(int result) {
//Hide white View
}
}
Note: I didnt test the code but i think more or less is ok
AsyncTask
I need to display progress icon in button so that user can interact other GUI elements while background task is processing.
I have searched in Android developer site and found that we can use animated drawables but don't know how to use them. Please advise on the same.
The very simple way to do this without using the animated drawable is to use "PregressBar" component in the design layout xml. When u need to show it, just set it's visibility property to visible and when you need to hide it, u can set it's visibility property to GONE. But remember this is UI task so when u need to do this with non-UI thread, u need to use Handler to set the status of "ProgressBar" component at runtime.
Below id the component in the layout file.
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ProgressBar>
Below is the code written in java file
ProgressBar prg;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
prg=(ProgressBar)findViewById(R.id.ProgressBar1);
prg.setVisibility(ProgressBar.GONE);
}
public void start_background_process()
{
// starting the process
prg.setVisibility(ProgressBar.VISIBLE);
new Thread(new Runnable()
{ public void run()
{
// Do your background stuff here which takes indefinite time
mHandlerUpdateProgress.post(mUpdateUpdateProgress);
}
} ).start();
}
final Handler mHandlerUpdateProgress= new Handler();
final Runnable mUpdateUpdateProgress = new Runnable() {
public void run() {
// ending the process
prg.setVisibility(ProgressBar.GONE);
}
};
If the default progress indicator is good enough for you (i.e. the spinning wheel), then you can just use ProgressBar. To change it from a normal progress bar to a spinning wheel, use progressBar.setIndeterminate(true).