saving the items displayed in listview in android - android

I am showing list of all the applications installed on the phone with the help of the packagemanager in the listview and there is a checkbox along with every application name shown in the list. I want to save the name of the applications against who the user has selected the textbox. The saved items will be used to generate a list of favorite apps.

You can Save it in the your database while the user presses on the check box and delete if it is already present in your database if the user unchecks it.You can use listener and put your code of saving inside your listener.

You should add a listener to your checkboxes => OnCheckedChangeListener
You will then be notified each time the state of the checkbox change, if the checkbox is checked, you can add the element to a list, if it is unchecked, you can remove the element from your list.
This requires you to have your own adapter thought.
Good luck and have a nice day

You need to make custom listview with checkboxes : here is one example for you.
You will need to have one Button below/above the Listview clicking on what you can take all the items and store it into your database : a complete Articale for that.
Now you can fetch the data from database anytime to show those favourite apps.

Related

How to save old position of an element in sharedpreferences after Search filtering the listview

I implemented the code for filtering and also saving the position of the selected element in the listview. After the user makes search in the listview via editText a new list is created. When the user clicks on the element the position of it is being saved in sharedpreferences. By reopening the app, this position is needed but not the position from the filtered listview. It should be the right position of the original one. I didnt find any way to do this in my code.
I would really appreciate any help.
Thank you.
Saving position is not a convenient way to achieve the solution. Rather you need to store any unique value of the list.
Suppose, you are showing a list of Person and filtering the list based on user search. So, every Person will have one id say, p_idwhich is unique. Try to save p_id in your SharedPreference.
Then after reopening the app check the p_id of original list and mark then check or uncheck.
Your element should have its position as a field. Initialize the position during initialization or addition to the list.

How to know what item is selected ina recyclerview via checkbox?

I have a question related to recyclerview and I would like to know how can I recognize what element is selected from a recyclerview whose items has a checkbox each one.
I am using clean architecture and one of my layouts has an spinner where I can select a city and i make an http post request and the response are all the offices in this city. I take all this offices and insert in my layout but all this items has a check box each one and I have to recognize which office I selected and I only can choose one of them.
How can I recognize which item is selected and how can I make to force user to only select one of them?
You can use simple logic for that,
Generally i used to store Recyclerview index for that,we can use SetChecked listener on checkbox in recyclerview adapter, when you check any checkbox, store position value in any variable and after that you can get value from list or array which is used to store all offices data of this particular index.

Dynamically adding place holder list items to ListView AND updating source data set with user input

I have an empty ListView where the user should be able to add each list item manually at the press of a button. When the user clicks on the button, I have a place holder list item appear which contains an EditText. When the user edits the text and it loses focus, I want the source data set to be updated with the users input.
Dynamically add elements to a listView Android
Up to now, I found this answer which uses an ArrayAdapter that connects an ArrayList and my ListView but from my understanding, this only updates the ListView when the ArrayList is updated. To clarify, I want to do the opposite, i.e when the list item is changed within the ListView, I want the appropriate ArrayList (or whatever data source which would make this easier) item to be updated.
I'd appreciate any help with this.
Thanks in advance!
I would suggest storing the position you focus on, then when it loses focus, write the new data to the item in your arraylist by calling getItem(position); followed up by notifyDatasetChanged();

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.

Categories

Resources