javaandroidlistviewspinnercheckedtextview

Creating multiple selection list Android


I would like to add a form of input in my app where a list of options appear and multiple choices can be selected. I would use a spinner, but that only allows one option to be selected. I would then need for the options selected to be sensed for me to perform further operations with this. I think I would need something involving a checkedlistview but I am not sure. What would be the best way to go about doing this? I hope my situation is understood.


Solution

  • Use checkedlistview it Help you

    ListMain.Java

    import android.annotation.SuppressLint;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    
    @SuppressLint("ShowToast")
    public class ListMain extends Activity {
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_main);
            ListView mylist = (ListView) findViewById(R.id.companionsearch_listView1);
            String[] list={"one","two","three"};
            ArrayAdapter adapter = new ArrayAdapter<String>(ListMain.this,android.R.layout.simple_list_item_multiple_choice,list);
            mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            mylist.setAdapter(adapter);
    
        }
    }
    

    activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
    
        <LinearLayout
            android:id="@+id/bottombarbuttonlayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:baselineAligned="false"
            android:weightSum="3" >
    
            <ListView
                android:id="@+id/companionsearch_listView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:background="#ffffff" >
            </ListView>
        </LinearLayout>
    
    </RelativeLayout>
    

    Output:

    enter image description here