Hi,

I think you need to set the Onclik Listner for the ListView in the
Ocreate Method.


And also I need a help from you..!

CAn you tell me how to display Array of Strings to List.




On Jan 5, 3:08 am, flashfreakmx <[email protected]> wrote:
> Right now I am extending Activity and populating 2 list views
> dynamically.
> How do I override the onListItemClick method for the lists if I am
> extending Activity?
>
> package com.thinknew.budget;
>
> import android.app.Activity;
> import android.content.Intent;
> import android.database.Cursor;
> import android.os.Bundle;
> import android.view.Menu;
> import android.view.MenuItem;
> import android.view.View;
> import android.widget.ListAdapter;
> import android.widget.ListView;
> import android.widget.SimpleCursorAdapter;
>
> public class Budget extends Activity {
>
>     private static final int ACTIVITY_CREATE=0;
>     private static final int ACTIVITY_EDIT=1;
>
>     private static final int INSERT_ID = Menu.FIRST;
>     private static final int DELETE_ID = Menu.FIRST + 1;
>
>     ListView inlist;
>     ListView outlist;
>
>     private BudgetDbAdapter mDbHelper;
>
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle icicle) {
>         super.onCreate(icicle);
>         setContentView(R.layout.budget_list);
>         mDbHelper = new BudgetDbAdapter(this);
>         mDbHelper.open();
>         fillData();
>     }
>
>     private void fillData() {
>
>         Cursor inCursor = mDbHelper.fetchIn();
>         startManagingCursor(inCursor);
>
>         // Create an array to specify the fields we want to display in
> the list (only TITLE)
>         String[] fromin = new String[]{BudgetDbAdapter.KEY_TITLE,
> BudgetDbAdapter.KEY_AMOUNT};
>
>         // and an array of the fields we want to bind those fields to
> (in this case just text1)
>         int[] toin = new int[]{R.id.singletitle, R.id.singleamount};
>
>         // Now create a simple cursor adapter and set it to display
>         ListAdapter in =
>                     new SimpleCursorAdapter(this, R.layout.budget_row,
> inCursor, fromin, toin);
>
>         inlist = (ListView) this.findViewById(R.id.listin);
>
>         inlist.setAdapter(in);
>
>         //setListAdapter(in);
>
>         Cursor outCursor = mDbHelper.fetchOut();
>         startManagingCursor(outCursor);
>
>         // Create an array to specify the fields we want to display in
> the list (only TITLE)
>         String[] from = new String[]{BudgetDbAdapter.KEY_TITLE,
> BudgetDbAdapter.KEY_AMOUNT};
>
>         // and an array of the fields we want to bind those fields to
> (in this case just text1)
>         int[] to = new int[]{R.id.singletitle, R.id.singleamount};
>
>         // Now create a simple cursor adapter and set it to display
>         SimpleCursorAdapter out =
>                     new SimpleCursorAdapter(this, R.layout.budget_row,
> outCursor, from, to);
>
>         outlist = (ListView) this.findViewById(R.id.listout);
>
>         outlist.setAdapter(out);
>
>         //setListAdapter(out);
>     }
>
>     @Override
>     public boolean onCreateOptionsMenu(Menu menu) {
>         super.onCreateOptionsMenu(menu);
>         menu.add(0, INSERT_ID, 0, R.string.menu_insert);
>         menu.add(0, DELETE_ID, 0,  R.string.menu_delete);
>         return true;
>     }
>
>     @Override
>     public boolean onMenuItemSelected(int featureId, MenuItem item) {
>         switch(item.getItemId()) {
>         case INSERT_ID:
>             createNote();
>             return true;
>         case DELETE_ID:
>             mDbHelper.deleteNote(inlist.getSelectedItemId());
>             mDbHelper.deleteNote(outlist.getSelectedItemId());
>             fillData();
>             return true;
>         }
>
>         return super.onMenuItemSelected(featureId, item);
>     }
>
>     private void createNote() {
>         Intent i = new Intent(this, BudgetEdit.class);
>         startActivityForResult(i, ACTIVITY_CREATE);
>     }
>
>     @Override
>     protected void onListItemClick(ListView l, View v, int position,
> long id) {
>         super.onListItemClick(l, v, position, id);
>         Intent i = new Intent(this, BudgetEdit.class);
>         i.putExtra(BudgetDbAdapter.KEY_ROWID, id);
>         startActivityForResult(i, ACTIVITY_EDIT);
>     }
>
>     @Override
>     protected void onActivityResult(int requestCode, int resultCode,
>                                     Intent intent) {
>         super.onActivityResult(requestCode, resultCode, intent);
>         fillData();
>     }
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to