I have an add button, a textbox called edittext, and a listview. When I click the add button data currently in edittext should move to list view. How can I make this happen?
set ArrayAdapter<String> for your
ListView
use insert method of
ArrayAdapter for move string from
EditText to ListView
http://developer.android.com/reference/android/widget/ArrayAdapter.html
"edittext should move to list view".. do you mean focus to be moved to listview OR Editext must disappear and listview must appear?
To handle focus you could use setFocusable() http://developer.android.com/guide/topics/ui/ui-events.html#HandlingFocus
For second option, you could hide widgets in event handlers.
#GSree it is very clear that user569553 wants that when he/she clicks on add button tha data of edittext feild should move to list.
so simply get data using getText() method and the go through this link.
best explanation i have ever found about implementation of getView() and listview.
http://android.amberfog.com/?p=296
If you're using an in-build list adapter such as ArrayAdapter or SimpleAdapter, then all you need to is add the data from EditText.getText() to your data collection, create a NEW list adapter, then when you call setListAdapter() the listview will be refreshed with your new item added.
Related
I'm new to Android and can't quite figure out the right approach for the problem I'm trying to solve. I have an ExpandableListView with several items. Each item has an EditText, except the last item has a button. The contents of the EditTexts are to be loaded from the database. When the button is clicked or when the activity is navigated away from, I want to save the contents of each EditText to my database.
I'm not sure what to call from the activity's class, what to call from my adapter, and how exactly to access each item appropriately. Code is welcome but not necessary, I'm just looking for guidance on the general approach. Thanks.
I'd recommend putting a method in your adapter called saveAllValues. It iterates through the list of objects in the adapter and saves them to the database. Call this when your button is clicked and in your activity's onStop() method (which is called when the activity is no longer visible).
You should have your activity fetch the values for the item IDs in an AsyncTask in its onCreate method. Then pass the list of id/value pairs to the adapter in its constructor. It should maintain this list so it can go back through it and save the IDs and values to the DB.
Hope my answers in these links help:
Values of counter changes after scrolling ExpendableListView shows how to maintain the list inside the adapter and how to get list from the activity.
Remove the divider view in the expandablelistview last item shows how to make the last child different from the others.
In my android application, I have one spinner box and two edit text box for adding item.When I click on add button all the data will store in database and display in below Item list (listview display in my first image) by refreshing listview.
My problem is, when I click on add button at a time only one list is display and listview heading is also gone.
May be this problem is raised due to refreshing of listview.
I searched on google and found notifyDataSetChanged() method is used for refreshing list view but I don't know how notifyDataSetChanged() method is used in fragment?
Does anybody know how to use this method in fragment?
I am new to fragment. In my app all the java code is developed using fragment activity, and xml file is simple layout.(LinearLayout/RelativeLayout)
You can see my screen here:
1)First image show list heading.
2)Second image show List item.
You need to setAdapter again to your listview after adding new data. it will show new data int listview.
if not get, post your code where you setAdapter to listview.
You have to first add item in Arraylist/List which you passed in Adapter then after you can call below code..
adapter.notifyDataSetChanged();
listView.invalidateViews();
I want to add editText on click on button in listview.
i have created adapter for this to add edittext to listview.
but problem is only one edittext is in Listview. i want to create more than one when click on button.
Please help
Your ListView is (should be) backed by some sort of Adapter, which in turn, should be wrapping a Collection of data objects, perhaps a List or String[].
Upon click of the button, you should add the data to the Collection that is wrapped by the Adapter, and then notify the Adapter with notifyDataSetChanged()
There's a good tutorial at http://www.vogella.com/tutorials/AndroidListView/article.html
I have a ListActivity which gets its data from a database query. I also have a custom adapter which extends simple cursor adapter.
To show the customised content, I have overridden the newView and bindView methods.
Each element of the view has:
TextView containing a title
ImageView containing number of stars - the image shown is changed based on a value obtained from the database
A button - the button text changes on clicks (Favourite/Make Favourite), and triggers a database update event.
My problem is this - when I scroll the ListView, the changes I made seem to disappear .. for instance, the first item is marked favourite, and the list is scrolled ... when I come back to the first item, the text reverts back to its previous value, although internally the db has been updated.
I read that the notifyDatasetChanged() is not right for this case as the adapter should be notified of the database changes. I am trying to use the reQuery() method, but do not know where to place it.
Should I place the reQuery() in the onClick method of the button? If not, where should it be placed?
What so ever Adapter is you are using must have getView Method.. Whenever a list is scrolled this getView Method got called for all the listItem in the view. Make Sure in the getView Method. That the view is getting generated dynamically.
It should check for clicked or changed value.
to update the list without scrolling your have to call listView.getAdapter().notifyDataSetChanged()
Check the following link. here i mentioned a complete code to use listview properly. Using this we can achieve any listview behavior. We can embed animation also.
Change ListView background - strange behaviour
Hope this help :)
If you have extended BaseAdapter ,
after data is changed call , listView.setAdapter() and in getView() , update the view's data too.
Use SetListAdapter with ArrayAdapter to display the list. Use ConvertView to avoid inflating View.
if (convertView==null)
{
//inflate your list
}
I am on Android 2.1 and I have one multi column Custom listview Using BaseAdapter with an editable edittext at the end of the listview. If the data in the listview do not contain the data of user choice then user should be able to enter data. If the data is already there in the list user will be able to select the data using custom selector. If a selection is made in the list view and user wanted to enter data in the text field at the bottom after selection then the marker in the list view should be unselected. I tried to use onclick() method on edit text using click listener. First time when it is clicked, edit text is getting focus and onclick() method is not fired. And when it is clicked second time, onclick() method is fired and notifyDataSetChanged() method is called. I tried to call the notifyDataSetChanged() method from the Focus Listener, list view selection is gone in my first attempt and edit text is not receiving any data input from the keyboard (frozen).Please help. Thanks, Venkat
Finally I fixed it. notifyDataSetChanged() on focus gained of edittext is recursively calling itself.Hence this issue was there. So, rather than calling notifyDataSetChanged() from focus listener I used a method in the activity to update the list from the focus listener of the edittext. Hence there was no issues of recursion with notifyDataSetChanged().