0

This is my list i want My problem is when i scroll list view then the check boxes(which are the items of this List ) are automatically checked ex - if i checked first then 4 automatically being checked.

My first goal:

 1. want to stretch my list to full i will wrap it into Scrollview  how
 2. i can prevent it to automatically checked

.

<ListView   
android:id="@+id/ListViewProducts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_span="2"
android:clickable="true"
android:isScrollContainer="true"
android:saveEnabled="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarSize="10sp"
android:scrollbars="vertical" >
</ListView>
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95

5 Answers5

2

Create your own BaseAdapter.

Keep in mind, that ALL views in your listview you see are temporary. They will be recycled when you'll scroll away. The reason is - you can have >9000 elements in your list. So, the way you create views must depend on some kind of (!) data.

Here is nince tutorial on how to create your own list.

Make X-th checkbox depend on X-th boolean in the list. A bit confusing first time I know, but this is the best way.

class MyAdapter extends BaseAdapter{

    List<boolean> myCheckBoxes;

    boolean getItem(int arg0){

        return myCheckBoxes.get(arg0);

    }

    View getView(int arg0, View arg1, ViewGroup arg2){

        ...
        ...//See article
        myView.setChecked(getItem(arg0));

        ...
        return myView;

    }

And in your activity

ListView myListView;
...
myListView.setAdapter(new MyAdapger(...));
UnknownJoe
  • 599
  • 5
  • 14
  • 30
  • yes but my problem starts from here Now i want to get the status of check boxes i'm using ListView.getAdapter().getView(int Position,null,null); to find the view but its not giving me the right view and its state – Trikaldarshiii May 01 '12 at 09:19
  • 1
    @Photon they wont give you the right view because the listview's views are temporary. to save information about a listview item you need to assign a listener and save its data to another data source (eg an array) – Joe May 01 '12 at 10:05
  • Make your views "equal" to some data collection. And get info from that. E.g. isSelected(int position){return myCheckboxes.get(position);} – UnknownJoe May 01 '12 at 10:07
1
  1. You can't put a listview into a scrollview, two views scrolling in the same direction will not work nicely. Just put the listview in your non scrolling layout (frame- , list-, relativelayout).
  2. Use an Adapter that sets every listview's row's views according to the data to be displayed.
Bondax
  • 3,143
  • 28
  • 35
1
  1. ListView already extends ScrollView and doesn't need to have another one to surround it.

  2. try looking at this post on creating custom listView items. you can implement a checkBox in them and make is have android:checked="false"

thepoosh
  • 12,497
  • 15
  • 73
  • 132
1

ListVew already extends ScrollView no need to implement it on ListView

for AutoCheck follow this link:

Check box checked Automatically in listview when scrolling the list.

Community
  • 1
  • 1
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
1

There's no need to implement scrollview in listview becoz it is already extends to scrollview. I think your listview is not able to handle the recycling of items properly.So to solve this problem go through the below link.

Getting an issue while checking the dynamically generated checkbox through list view

Community
  • 1
  • 1
himanshu
  • 1,990
  • 3
  • 18
  • 36