Android activity indicator?

How can I show activity indicator in Android? Is there any Android library this method? If not, tell me the methods used to display the activity indicator in Android.

+44
android android-layout android-activity
Feb 17 '11 at 6:13
source share
4 answers

do something like this

ProgressDialog mDialog = new ProgressDialog(getApplicationContext()); mDialog.setMessage("Please wait..."); mDialog.setCancelable(false); mDialog.show(); 
+52
Feb 17 '11 at 6:31
source share

The most direct equivalent of the iOS activity indicator in Android is the ProgressBar, but it is set to undefined. That way, you can leave the view in your layout and it will provide you with spinning animation.

 <ProgressBar android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/ctrlActivityIndicator" android:indeterminateOnly="true" android:keepScreenOn="true" /> 

You can use this to tell the user some background activity.

+75
Oct 24
source share

There are two other ways to display an activity indicator without using the modal ProgressDialog.

You can use ImageView in your layout and apply animation to it. Refer to the developer's site .

 public void startAnimation() { // Create an animation RotateAnimation rotation = new RotateAnimation( 0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotation.setDuration(1200); rotation.setInterpolator(new LinearInterpolator()); rotation.setRepeatMode(Animation.RESTART); rotation.setRepeatCount(Animation.INFINITE); // and apply it to your imageview findViewById(R.id.myActivityIndicator).startAnimation(rotation); } 

Or you can use xml-drawable to describe a background image that will have some kind of spinning animation:

First, we describe drawable (in ie / res / drawable / my-indicator.xml)

 <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/spinner_black_76" android:pivotX="50%" android:pivotY="50%" android:framesCount="12" android:frameDuration="100" /> 

Then set it against the background of some kind

+17
Feb 17 2018-11-11T00:
source share
 public class Mp3cutterActivity extends Activity { MP3Class mp3obj = null; TextView tv; MP3Class mp3classobj = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Context thiscontext = this.getApplicationContext(); mp3classobj = new MP3Class(thiscontext); setContentView(R.layout.main); Button btn = (Button)findViewById(R.id.startbutton); tv = (TextView)findViewById(R.id.textview1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //show a wait indicator as well as the function that calls walkSdcard try { new SearchSdCard(Mp3cutterActivity.this).execute(); // copyProtector.doCopyProtection(); } catch (Exception e) { System.out.println("in search SD card " + e.getMessage()); } } private void domp3stuff() { // TODO Auto-generated method stub } }); } } class SearchSdCard extends AsyncTask<String, Void, Boolean> { Context context; public ProgressDialog dialog; public SearchSdCard(Activity activity) { this.context = activity; } protected void onPreExecute() { dialog = new ProgressDialog(context); dialog.setMessage("wait for a moment..."); dialog.show(); } @Override protected Boolean doInBackground(String... params) { // TODO Auto-generated method stub boolean retval = true; mp3classobj.searchSdCard(); return retval; } @Override protected void onPostExecute(Boolean result) { // TODO Auto-generated method stub if (dialog.isShowing()) { dialog.dismiss(); tv.setText("mp3 cutter is an app which cuts down a chunk of memory \nfrom your sdcard by \ndeleting the .mp3 files and more \nyou were made a BAKRA :-)"); if(!result){ tv.setText("error occured !!"); } } } //refer below comment for the MP3class.java file details } 
+4
Nov 29 '12 at 12:50
source share



All Articles