Hi all,
I'm fairly new to android development, so sorry if this is a dumb question.
I would like to nearly replicate the e-mail browsing list (one checkbox, as well as one or two textviews). the user can either click on the checkbox to 'select' one or more rows, or they can click on the other portion of the row to switch to a more detailed view of that row's data.
Visually, a ListView with the android.R.layout.simple_list_item_multiple_choice layout is about right, however, i have overridden the onListItemClick method of the ListActivity to bring up the detailed information screen. when I did that, i could no longer select multiple rows.
Can anyone help me either tweak the existing implementation, or help me write new code to achieve this effect?
code is here for reference:
Oh, I forgot to mention: I tried to change to use a custom layout, but then the onListItemClick was not being executed. was there something else i needed to add there (other than the layout (I created the layout in xml) and changing the MyCursorAdapter instantiation)?
Thanks
I'm fairly new to android development, so sorry if this is a dumb question.
I would like to nearly replicate the e-mail browsing list (one checkbox, as well as one or two textviews). the user can either click on the checkbox to 'select' one or more rows, or they can click on the other portion of the row to switch to a more detailed view of that row's data.
Visually, a ListView with the android.R.layout.simple_list_item_multiple_choice layout is about right, however, i have overridden the onListItemClick method of the ListActivity to bring up the detailed information screen. when I did that, i could no longer select multiple rows.
Can anyone help me either tweak the existing implementation, or help me write new code to achieve this effect?
code is here for reference:
Code:
public class EditRecordsMenu extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
if(i.getData() == null) {
i.setData(CONTENT_URI);
}
Cursor c = managedQuery(getIntent().getData(), null, null, null, null);
setListAdapter(new MyCursorAdapter(this,
android.R.layout.simple_list_item_multiple_choice,c,
new String[] {DATE},new int[] {android.R.id.text1}));
}
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
setViewBinder(new MyViewBinder());
}
}
private class MyViewBinder implements
SimpleCursorAdapter.ViewBinder
{
public boolean setViewValue(View view, Cursor cursor, int columnIndex)
{
if(columnIndex==cursor.getColumnIndex(DATE)) {
String date = MileageData.getDateFormatter().format(cursor.getLong(columnIndex));
((TextView)view).setText(date);
return true;
}
return false;
}
}
protected void onListItemClick(ListView l, View v, int position, long id) {
Uri uri = ContentUris.withAppendedId(getIntent().getData(), id);
String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
// The caller is waiting for us to return a note selected by
// the user. The have clicked on one, so return it now.
setResult(RESULT_OK, new Intent().setData(uri));
} else {
// Launch activity to view/edit the currently selected item
startActivity(new Intent(Intent.ACTION_EDIT, uri));
}
}
}
Oh, I forgot to mention: I tried to change to use a custom layout, but then the onListItemClick was not being executed. was there something else i needed to add there (other than the layout (I created the layout in xml) and changing the MyCursorAdapter instantiation)?
Thanks