I'd like to insert a progress spinner in AutoCompleteTextView while another class performs the autocomplete function.
I read about the frame Layout ed fixing it in the EditText but the question is:
How to set the progress spinner? And how to control it?
Use this in the layout where you want to display the ProgressBar. You can set the visibility, View.VISIBLE, View.GONE to make it visible and invisible.
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
Related
I want that my button looks like a spinner, because I will show a special dialog if the button is clicked. I use Theme.MaterialComponents and tried following but it's not working:
<Button
android:id="#+id/btMusclegroups"
style= "?spinnerStyle"// or style="#style/Widget.AppCompat.Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The button still looks solid and not like a spinner.
Desired result
I want that my button looks the same as following Spinner:
<Spinner
android:id="#+id/btMusclegroups"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
I could use a Spinner with OnTouchListener and a dummy adapter (I don't need the adapter, my dialog knows all the data it needs already) but I'd prefer the above way - is this somehow achievable?
Create a container and add an image view containing the dropdown symbol for the spinner and a button. Add an OnClickListener to the button that calls the dialog and updates the text of the button. Don't forget to style the button as NoBackground.
I have a button Add new address and when it is pressed, I want to show EditText fields to collect the new address details. Is there any layout to do that. Or hiding the text fields when the Button is unpressed, is that the only way to do this?
Define the edit box in a layout as below -
<LinearLayout
android:id="#+id/exp_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/exp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
</LinearLayout>
And now use the layout id to get the view like below.
LinearLayout l=(LinearLayout)findViewById(R.id.exp_linear_layout);
And just toggle the visibility on button click event -
l.setVisibility(View.GONE) and vice versa.
I hope it will help u.
There is no built in framework to do it. You can do this by setting View.SetVisibility() to visible or gone. Initially the button is visible but textfield is invisible. When user click on the button, you can set this button visibility invisible or gone and visible the text fields.
I have a GridView which shows a grid of 15 Views for the first time. Then, on click of a button, I add 5 more grid views. So, my question is: How to add a ProgressBar at the bottom of a page, when those 5 Views are loading ? Like a spinner loading and the 5 Views get updated.
Hi i have a tab host tabwidget for tabs and gridview inside framlayout..now if i want the progressbar then should i need to inclue this linearlayout after frame layout or inside frame laoyout?
Add this below your GridView in the XML.
<LinearLayout
android:id="#+id/linlaProgressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ProgressBar
style="#style/Spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" />
</LinearLayout>
And in your Activity, where you are loading the data (assuming, it is an AsyncTask), in your onPreExecute() show it:
#Override
protected void onPreExecute() {
// SHOW THE BOTTOM PROGRESS BAR (SPINNER) WHILE LOADING MORE PHOTOS
linlaProgressBar.setVisibility(View.VISIBLE);
}
And in the onPostExecute(), hide it:
#Override
protected void onPostExecute() {
// SHOW THE BOTTOM PROGRESS BAR (SPINNER) WHILE LOADING MORE PHOTOS
linlaProgressBar.setVisibility(View.GONE);
}
If you are not using an AsyncTask, then set the visibility to View.VISIBLE at the start of the method where you start downloading the data and set it to View.GONE either after or just before you set the Adapter.
EDIT: Adding additional info.
Couple of things.
You are downloading data off the Internet for which, I would recommend switching to AsycnTask instead of using a conventional () Method.
Check out my answer a few days ago on a similar question here: https://stackoverflow.com/a/13265776/450534
In that answer, you will find a complete solution that will suit your exact needs. Well, almost entirely anyway. You may have to make a few modifications and adapt to a few things yourself. But by and large, it will answer all your questions. I use it in my apps and they function as you say, the Google Play loading text at the bottom. And it really is complete. :-)
You need to create custom view for that and inflate it and add as bottom view in gridview
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button android:text="Load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
<ProgressBar
android:layout_width="25.0dip"
android:layout_height="25.0dip"
android:layout_centerInParent="true"
android:visibility="gone"
/>
</RelativeLayout>
now inflate this view and show the progressbar at bottom of gridview
You can set button as bottom with this when you click just visible the progressbar
Just add a ProgressBar in your layout, set its visibility to VISIBLE or GONE whenever you want to show/hide it.
Add a in the xml of GridView and set its property "alignParentRight = true" and "visibility = invisible" . In your activity , use Async task class and on its preExectue method set set its visibility to visible
pb.setVisibility(View.VISIBLE);
In doInBackground method load your images and finally in onPostExecute method make this progress bar invisible.
pb.setVisibility(View.INVISIBLE);
execute this async task class on click of load button.
This is an easy tutorial for understanding asyncTask
http://androidresearch.wordpress.com/2012/03/17/understanding-asynctask-once-and-forever/
Or threads can be used instead of async task.
I'm using a ListView with a custom adapter to receive a JSON response and put it into a nice list - works great.
I'm now testing various exceptions and error handling and am catching errors received from my web API within the Android app. This all works great, handles well - but for the life of me I can't work out how to change the 'empty view' of a ListView once it has been set once.
It's within a fragment, if that makes any difference - but the ProgressBar and ListView are defined in an XML layout which is inflated in the Fragment. I have a TextView also inside there which contains some error text - I want to know how to switch the ProgressBar out for the TextView onError()!
Edit: Currently the ListView uses the ProgressBar as the empty view - I want to know how to later change this to another view - XML defined or programmatic.
The UI thread is not being locked as all API calls are carried out on an AsyncTask, so that's not the issue.
ListView.removeAllViews() caused a fairly imminent crash.
Apologies if this is trivial...
You could define the empty view to be a FrameLayout and put whatever you want the empty state be inside that view and change it the way you'd change contents of any other view.
I have two empty views for my ListView. One is ProgressBar which I shows while I am loading data from database or server. Other is TextView, which I shows when I got error or have no data.
I put my ListView, ProgressBar and TextView in FrameLayout. And set visibility of both ProgressBar and TextView to Gone.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="#+id/my_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="#+id/empty_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:text="#string/no_contacts_found"/>
<ProgressBar
android:id="#+id/empty_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>
Before loading data from database or server, I change visibility of ProgressBar to Visible and set it as empty view of my ListView. So my ListView starts showing ProgressBar, indicating user that data is still loading.
If I got error or got no data from database or server, I set visibility of ProgressBar to Gone and change visibility of TextView to Visible. And then set TextView as empty view of my ListView.
I just found this code in an old project, should work fine:
View emptyView = inflater.inflate(R.layout.id_of_your_layoout_file, parent, false);
getListView.setEmptyView(emptyView);
I have a LinearLayout that will have a cancel button and a progress bar, where the progress bar is 70% and the cancel button is 30%, like so:
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ProgressBar
android:id="#+id/uploadProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_weight=".7"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
<Button
android:id="#+id/uploadCancelButton"
style="#style/TitleBarButton"
android:layout_width="0dp"
android:layout_weight=".3"
android:layout_height="wrap_content"
android:text="#string/cancel_btn"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
This works fine, however I realized that actually I either want to show the progress bar or a text view, where the text view could be a small status message (if say the upload failed).
I tried putting a TextView in the the above LinearLayout and having its visibility set to "gone" by default and with the weight set the same as the progress bar. In the code I would only set either the progress bar to visible or the text view, and the other I would set to gone. However the android system appeared to contribute the invisible items weight to the total. I even tried using android:weightSum="1.0" in the LinearLayout xml attributes but that then my button was no longer visible as even though the text was gone, it took space.
ViewFlipper is what you are looking for.
It is very simple to use. You put the views you want to toggle inside the ViewFlipper exactly the same way like you would place them within a Layout inside XML. Then from code you call setDisplayedChild() on the ViewFlipper object containing your views. The parameter of this method is the index of the view that you want to be shown.