-1

I am creating an app in which I can search for files and delete it.

    searchstring = receivedmsg.getString("mysearch");
    tv.setText("Search Results for " + searchstring);   

    searchForFileNameContainingSubstring(searchstring);

    //ListAdapter myadapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, resList);
    //lv.setAdapter(myadapter);

    CustomAdapter adapter = new CustomAdapter(DataFetcher.this, android.R.layout.simple_list_item_1 , resList);
    lv.setAdapter(adapter);

Searched results are showing in listview. How can I add checkboxes in listview? Already searched on google but it's not working. How can I achieve that?

vinS
  • 1,417
  • 5
  • 24
  • 37
shubham kumbhar
  • 47
  • 1
  • 2
  • 10

1 Answers1

2

Create custom layout with any name you want: for example:

single_item_list.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="6dip" >

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="CheckBox" />

        <TextView
            android:id="@+id/code"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/checkBox1"
            android:layout_alignBottom="@+id/checkBox1"
            android:layout_toRightOf="@+id/checkBox1"
            android:text="TextView" />

    </RelativeLayout>

Now in your customAdapter:

CustomAdapter adapter = new CustomAdapter(DataFetcher.this, R.layout.single_item_list , resList);

and handle functionalities in customAdapter

Muhammad Saad
  • 713
  • 1
  • 9
  • 31