Displaying Alert Message Box on click event - android

I have an application where I have Tab Host. I have certainly four tabs in my Tab Host and one of my tab contains a list of some elements. Now When a user click on the element of the third Tab he is supposed to switched to the first tab and the data of the list element gets displayed there. But when the user initially tries to click on the first Tab without selecting any element from the list of third tab, I need to display the Alert Message that "Please select an item form the List"
I wonder how to do that particularly?
Thanks,
david

use AlertDialog.

Toast.makeText(this,"Please select an item form the List",Toast.LENGTH_LONG).show();
use it on your click event.

You can use any of the above, but I feel its the logic that you're more interested in.
You might be having four different activities for each tab.
Create on more class, which will serve as your Bean class, which holds all the data to transfer information between classes.
Call this class as PrefBean.
Make all its variables static (as of now you'll be using only one to know whether user has selected any list item, and if yes, which one). This way, the variables will be globally available to all of your activities.
Have an integer in PrefBean which depicts whether something is selected or not in your third tab.
The logic goes as this:
Initially, your integer in PrefBean will hold something less than zero (say -1). This will show that nothing is selected as of then.
When user clicks in the first tab, your first activity will be invoked and it should check the value of that integer in PrefBean, display an error message to the user. If the value is negative, means nothing is selected, if its positive, it will give you the position of the row selected. Load anything depending on the row position selected
When user clicks on any row in your third tab's list activity, set your PrefBean integer == the row position selected.
I hope you got the logic

Related

Verify if there are any selected items in a gridview

im developing an app and implementing an onboarding to ask the user to select certain options that will be displayed in a grid view. I want the user to select and unselect and item for this im using a simple toggleSelected(){selected=!selected} declared in my item entry class.
I also have a button at the bottom that will be disabled if all the items in the gridview have isSelected() = false. What is the best way to check this?
Thanks for the help
In the model class which actually contains the data,the list which you provide to the adapter of the recyclerView , add a variable isSelected and set its default value to false, whenever a grid item gets selected, set it to true and when it gets unselected, set it to false. In this way you could travel that list and then know which all are selected and which are not.
One way would be to loop over all the elements and check if any is selected.
But that would be quite resource heavy.
I'd rather suggest that you keep a count of selected elements.
If count != 0, then enable your button.

Iterate through custom ListView to save checked checkboxes and spinners

I have Activity A that runs Activity B with a button click.
Activity B has a list view with custom rows:
some rows have a title and checkboxes.
and some rows have a title and a spinner .
each row the user either checks the preferred checkboxes or chooses from a spinner.
so far so good. my problem is , when clicking back to Activity A, how do I save all the choices?
and by save I don't mean just save his checked boxes but also get the values of his choices back to Activity A.
I don't want the choices to be saved even after I restart the app. only when the app is running .
So basically I need to :
1. get the user's choices and save their values (either from a spinner or from the checkbox)
2. save the ticked checkboxes the next time the user clicks to go to activity B
I thought about using onPause in Activity B , where I will get a reference to the listView, go through every row, see if there is a checkbox or a spinner there, and then somehow see what value is checked (if its checkboxes) and what value is selected(if its a spinner).
I don't know if it's the right approach or not, anyway I really need help here.

loading listview twice?

I have an activity on the top of it there are some buttons from which when a button pressed it loads the dialog with country list and when user choose choose the country it will load the channel list below buttons.
so when activity start it shows blank screen until user choose the country
so i want to show a list when activity will start and then same procedure will follow as above.
but how can i load two different listview?
i tried
acivity start
load the default country channel's list
buttonclick listener
perform click {
load the another list
}
using the base adapter class found here.
Just switch adapter to current list (this is the easy way to do it)
OR
In your android xml file, where you create your activity, create two listviews with different ids. First listView will have android:visibility="visible" (this one will be shown first) and the second one will have android:visibility="gone"(you will make this visible when you perform the click).
When you want to switch the lists, just set first listview visibility to View.VISIBLE and the other one to View.GONE, from code.
Don't forget to switch adapters for different lists (this may be a bug source)
I would do following
Have a flag like isCountrySelected
Change your adapter and onitemclick handler so that according to isCountrySelected, you either load channel list or country list.

How to higlight multiple items in a list in Android?

I have a ListActivity that presents a list of names from a database using a SimpleCursorAdapter. I want the user to be able to select 1 or more names by clicking them and then proceed to the next Activity. This should be a toggle, so that if the user clicks a selected name it will become de-selected. The underlying code is working fine, the problem is how to show the user which items are currently selected.
I looked at this solution: Android how to highlight a selection in a list and tried toggling .setSelected() on the TextView for the name. The problem is that the "selected" state apparently can only be true for one item in a list at a time. So if the user touches "Alice" then "Bob," only "Bob" will show as selected. Any thoughts on the best way to have a toggle-able highlight for multiple list items?
Have a look at the setChoiceMode method of the AbsListView class and its possible CHOICE_MODE_MULTIPLE parameter value.

List view row Selection

i have a simple list view control
my queries are:
1) how to set first row selected on start (after fill data in list view)
2) when i navigate by hardware button i got AdapterView.OnItemSelectedListener and color of row background change, but when i click i not get any OnItemSelectedListener and no row selected. How to select row on click.
3) when i change focus list row selection removed,
please any one with any solution, code example or articles
i search but no susses
with regards
Chandra Kant Singh
how to set first row selected on start
(after fill data in list view)
Call setSelection() on the ListView. However, this only will have a visual effect if the user entered your activity via the pointing device (trackball, D-pad, etc.).
How to select row on click.
You don't.
when i change focus list row selection
removed,
If I understand what you mean by "change focus", this is working as designed.
Please review this article on touch mode and the use of the "selected" state, then adjust your UI design to follow Android conventions. Selection is only used when the user navigates with the pointing device, not when the user uses the touch screen.

Categories

Resources