Iterate through custom ListView to save checked checkboxes and spinners - android

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.

Related

android - Is there a way to cache a View?

I have a complex listview. Every item in this listview has three EditTexts and two Checkboxes. Outside the listview is a Button for adding rows to the listview, one for continue and one to go back.
Continue and Back does both call something like:
setContentView(R.layout.stepX);
The problem:
If you press continue and then go back all items from the listview are empty. Is there a easy way to save the input or hold him in ram?
My current workaround is to create a Class for a listitem and if you continue every itemdata is read and saved to an arraylist. If you go back it read the arraylist and rebuild the listitems.

RadioGroup : I use onCheckedChangeListener method. How can I make it possible that if user select the already selected Button, the method still runs?

I use onCheckedChangeListener to return the result back to MainActivity and finish the current activity. But if user decides to use the default selected value, he'd like to re-click the radiobutton to save result. How can I do that?
Thanks
Edit:
In short, how do I know if a user selects an already selected radiobutton?
If user selects the selected value then nothing changes and this method won't get called but you can check whenever you want that which radio button in a radio group is selected it should work.
If you want to check whether user has selected a different option just compare the current selection with default selection.

Using checkbox in each listview item row, need to show selected item(s) name into another activity

I am using checkboxes in each listview item row, now I need to show selected item(s) name into another activity,here I am fetching data using a JSON parser.
I don't know how to get selected listview item name to another activity, I am using a submit button once the user has finished with checkbox selection, he/she just needs to click on submit and need to show selected item names into another activity. I know how to use the intent to send data to another activity.
I think you looking for a solution like I do before. Read this Tutorial, it will help ypu :-)

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.

Displaying Alert Message Box on click event

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

Categories

Resources