Question

The below is the code for the Subclass of ListFragment.

        @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SQLiteDatabase allDatabase2 = new TaskDatabaseManager(getActivity())
            .getWritableDatabase();
    Cursor allDetail = allDatabase2.rawQuery("Select "
            + TaskDatabaseManager.KEY_ROWID + ","
            + TaskDatabaseManager.TASK_TIMES + ","
            + TaskDatabaseManager.TASK_DESCRIPTION + " from "
            + TaskDatabaseManager.DATABASE_TABLE + " where "
            + TaskDatabaseManager.TASK_DATE + "= '"
            + LaunchActivity.selectedDate + "'", null);
    String[] fromColumns = { TaskDatabaseManager.TASK_TIMES,
            TaskDatabaseManager.TASK_DESCRIPTION };
    int[] toView = { R.id.Time, R.id.TaskDescription };
    allDetail.moveToFirst();
    if (allDetail != null) {
        setListAdapter(new SimpleCursorAdapter(getActivity(),
                R.layout.layout_for_cursor, allDetail, fromColumns, toView,
                0));
    }

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

     return inflater
    .inflate(R.layout.fragment_layout, container, false);
      //        return super.onCreateView(inflater, container, savedInstanceState);
}

Now as u can see i have set the choiceMode as ListView.CHOICE_MODE_MULTIPLE on the Overriden onViewCreated() method.

@Override
public void onViewCreated(View v, Bundle b) {
    super.onViewCreated(v, b);
    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
 }

but still nothing is like multiple choice is visible in the details.

Below is the code for my fragment_layout.xml

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainContentLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"
    />
  </LinearLayout>

Edited.This is layout_for_cursor

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutForDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:id="@+id/Time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="58dp"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/TaskDescription"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/Time"
    android:layout_below="@+id/Time"
    android:layout_marginTop="33dp"
    android:textAppearance="?android:attr/textAppearanceMedium" />

  </RelativeLayout>       
Was it helpful?

Solution

Adding android:background="?androind:activatedBackgroundIndicator" to your RelativeLayout in R.layout.layout_for_cursor will add the highlight functionality for the CHOICE_MODE_MUTLIPLE option of the ListFragment.

To capture these selected events, override the onListItemClick method and you will get a position back from it. From there, use the position to retrieve the desired entry.

OTHER TIPS

You have to use a layout that is checkable. Here is an implementation of a checkable relativelayout.

see this example: http://www.marvinlabs.com/2010/10/29/custom-listview-ability-check-items/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top