listactivity not responding to click


Last Updated:

  1. airswit

    airswit Member This Topic's Starter

    Joined:
    Dec 19, 2009
    Messages:
    5
    Likes Received:
    1
    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:
    Code (Text):
    1.  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="horizontal"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="wrap_content"
    6.     android:background="#ffffffff"
    7.     >
    8.     <TextView
    9.     android:layout_width="wrap_content"
    10.     android:layout_height="wrap_content"
    11.     android:id="@android:id/text1"
    12.     android:layout_weight="1"
    13.     android:background="#ff000000"
    14.     />
    15.     <CheckBox
    16.     android:layout_width="wrap_content"
    17.     android:layout_height="wrap_content"
    18.     android:id="@android:id/checkbox"
    19.     android:layout_weight="0"
    20.     />
    21.    
    22. </LinearLayout>
    23.  
    Java code:
    Code (Text):
    1. public class EditRecordsMenu extends ListActivity {
    2.     @Override
    3.     public void onCreate(Bundle savedInstanceState) {
    4.         super.onCreate(savedInstanceState);
    5.        
    6.         Intent i = getIntent();
    7.         if(i.getData() == null) {
    8.             i.setData(CONTENT_URI);
    9.         }
    10.         Cursor c = managedQuery(getIntent().getData(), null, null, null, null);
    11.         setListAdapter(new MyCursorAdapter(this,
    12.                 R.layout.record_list_item,c,
    13.                 new String[] {DATE},new int[] {android.R.id.text1}));
    14.         getListView().setOnCreateContextMenuListener(this);
    15.     }
    16.  
    17.     private class MyCursorAdapter extends SimpleCursorAdapter {
    18.  
    19.         public MyCursorAdapter(Context context, int layout, Cursor c,
    20.                 String[] from, int[] to) {
    21.             super(context, layout, c, from, to);
    22.             setViewBinder(new MyViewBinder());
    23.         }
    24.         private class MyViewBinder implements ViewBinder
    25.         {
    26.             public boolean setViewValue(View view, Cursor cursor, int columnIndex)
    27.             {
    28.                 if(columnIndex==cursor.getColumnIndex(DATE)) {
    29.                     String date = MileageData.getDateFormatter().format(cursor.getLong(columnIndex));
    30.                     ((TextView)view).setText( date);
    31.                     return true;
    32.                 }
    33.                 return false;
    34.             }
    35.  
    36.         }
    37.     }
    38.  
    39.     @Override
    40.     protected void onListItemClick(ListView l, View v, int position, long id) {
    41.         super.onListItemClick(l, v, position, id);
    42.         Uri uri = ContentUris.withAppendedId(getIntent().getData(), id);
    43.        
    44.         String action = getIntent().getAction();
    45.         if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
    46.             // The caller is waiting for us to return a note selected by
    47.             // the user.  The have clicked on one, so return it now.
    48.             setResult(RESULT_OK, new Intent().setData(uri));
    49.         } else {
    50.             // Launch activity to view/edit the currently selected item
    51.             startActivity(new Intent(Intent.ACTION_EDIT, uri));
    52.         }
    53.     }
    54.  
    Thanks!
     

    Advertisement

Share This Page

Loading...