I have a ListView, with different custom rows.
The last row contains a TextView and a Spinner. The Spinner works ok (when clicked the dropdown list is shown, when I choose an option it appears in the Spinner's prompt), but when I scroll up the list, the Spinner changes its value to the value in the first position (ie the string at position 0).
Why is this happening? And what can I do to stop this?
it will its the property create custonbaseadapter set getview and newview method
Advance List
Custom Apdapter
See this
Related
I have a scrollable listview that has 2 textViews, 3 imageButtons and 1 checkBox in each row.
In the Header of the listView, I have a delete button just above the column containing all the checkboxes of the listView.
I have to perform the delete operation of objects in the listView when 2 or more checkBoxes are checked randomly by scrolling the listView and thereafter the delete button at the top is clicked.
But the problem is that i am not getting the correct poition of the checkbox that was selected. Moreover, sometimes i get the correct position but still the object to be deleted passed is wrong. Hence the entire functionality is affected maybe due to the scrolling nature of the list.
Should i take the position in the holder of the adapter class and also bind the state of the checked or unchecked checkbox with my object.
And should I use checkBox.setOnCheckedChangeListener() or deleteButton.setOnClickListener().
If i use the latter one, then how to get all the corresponding objects of the list whose checkboxes were checked before pressing the delete button?
And where should all the related code be placed..in the listAdapter class or in the activity?
Please help me find a solution to this problem..
first of all in your getView() method you should set a specific Tag to each checkBox. For example: check1.setTag(position) then you should implement both OnCheckBoxChangeListener for your checkBoxes and OnClickListener for your delete button. As you know setting of onCheckBoxChangeListner have to be in getView() method. Then you add positions of list that their checkBox is checked to the a ArrayList with the help of getTag() method of chechBoxes in onCheckedChanged() method.
Try getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {}
When I click on item inside dropdown list in spinner view in Android - the value on spinner is changed to the one i clicked.
I would like to disable this behavior.
I just need the callbakck, that such click occur. Any ideas?
Thanks Dominik.
Override the getView() method of your Adapter. Set the same text for all positions.
There is custom view and a ListView, both are coupled as such if one changes its state other must change. I am able to control custom view if one item of ListView is selected.
If a item is selected in custom view, corresponding item in List view should become visible and text in it must be hilighted.
I tried
listView.smoothScrollToPosition(clueIndex);
no scrolling happens on execution of this line.
Second question -
How can I get access to TextView in a particular adaptor postion and change its text color outside OnItemLongClickListener() ?
Issue resolved, due to error clueIndex was always -1.
I have a listview with a textview as each item. I want to change the textcolor of the selected item. For this use the onItemSelected method to make the changes. Say first I select the 1st row, the first row's textcolor changes. Now when I select the 2nd row, its text color also changes, but I want the 1st row's color to change back to its default color. How do I do that, since in the onItemSelected I only get the refernce of the currently selected item and not the last selected. Is there any way other than holding a reference to the last selected view.
When first item is selected store its position in instance variable of your activity, lets name it currentlySelected. Then combine with this Android: Access child views from a ListView
in order to get the view at position currentlySelected and change it's textcolor.
Instead of doing it in Java, you can let android handles it in the xml file. See Color State List Resource.
I'm using the cool feature of the ListView to show a checkbox next to the item in the ListView.
I bind my list to an array of strings.
The onClick and onSelectedItem listeners get called fine, in this way I know the index of the "string" checked (or unchecked).
I'm storing all the checked strings into preferences (as a comma-concatenated-string), and everytime the activity becomes visible I would like to set the checked items back in the listview.
Is there a way of doing it? or the CHOICE_MODE_MULTIPLE doesn't allow to set the checked items?
note: I'm not using a custom view, since what I want to display is just a string and a checkbox. I've tried setSelection(index) but it should set the onlyone selected (highlighted) row.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,names);
m_playlists_list.setAdapter(adapter);
m_playlists_list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Use the setItemChecked method of ListView
Sets the checked state of the specified position. The result is only valid if the choice mode has been set to CHOICE_MODE_SINGLE or CHOICE_MODE_MULTIPLE.