Hi All,
I have a ListActivity with a custom layout, but when i overload onListItemClick method, the code is not called. can anyone help?!
XML code for the list item's layout:
Java code:
Thanks!
I have a ListActivity with a custom layout, but when i overload onListItemClick method, the code is not called. can anyone help?!
XML code for the list item's layout:
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/text1"
android:layout_weight="1"
android:background="#ff000000"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/checkbox"
android:layout_weight="0"
/>
</LinearLayout>
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,
R.layout.record_list_item,c,
new String[] {DATE},new int[] {android.R.id.text1}));
getListView().setOnCreateContextMenuListener(this);
}
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 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;
}
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, 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));
}
}
Thanks!