Sorry forget to say that the error was in the fillText function and started here: flightno.setText(flight.getString( flight.getColumnIndexOrThrow (flightDbAdapter.KEY_FLIGHTNO)));
On Mar 25, 12:32 am, Wouter <wouterg...@gmail.com> wrote: > ok I have figured out how i can get different actions but i have > another problem now. > I have, like i already said, a list of flights.. > when i click on a item in the list : > > �...@override > protected void onListItemClick(ListView l, View v, int position, > long id) { > > Intent intent = new Intent(TravelPlannerHome.this, > FlightView.class); > intent.putExtra(FlightDbAdapter.KEY_ROWID, id); > startActivityForResult(intent, ACTIVITY_VIEW);; > super.onListItemClick(l, v, position, id); > > } > > I have to go to the activity FlightView: > > Problem now is that he passes a rowid (unique id for database) but i > got this error: > 03-25 00:18:19.742: ERROR/AndroidRuntime(3947): Caused by: > android.database.CursorIndexOutOfBoundsException: Index 0 requested, > with a size of 0 > > This worked when i hadn't a seperatedlist! > How can i fix this? > > package com.ehb.mybuddy.TravelPlanner; > > import com.ehb.mybuddy.R; > import com.ehb.mybuddy.TravelPlanner.db.FlightDbAdapter; > > import android.app.Activity; > import android.app.AlertDialog; > import android.content.DialogInterface; > import android.content.Intent; > import android.content.DialogInterface.OnClickListener; > import android.database.Cursor; > import android.os.Bundle; > import android.view.Menu; > import android.view.MenuItem; > import android.view.animation.AnimationUtils; > import android.widget.TextView; > import android.widget.ViewFlipper; > > public class FlightView extends Activity { > > private FlightDbAdapter flightDbAdapter; > private Long mRowId; > > //TEXTVIEWS > private TextView flightno; > private TextView depCity; > private TextView depDate; > private TextView arrCity; > private TextView arrDate; > private TextView aircraft; > private TextView ticketno; > private TextView seat; > private TextView reminder; > > private static final int DELETE_ID = Menu.FIRST; > private static final int UPDATE_ID = Menu.FIRST + 1; > private static final int TRAVELPLANNER_HOME_ID = Menu.FIRST + 2; > > private static final int ACTIVITY_VIEW= 1; > private static final int ACTIVITY_EDIT = 2; > > private ViewFlipper viewFlipper; > private TextView animationText1; > private TextView animationText2; > private TextView animationText3; > private TextView animationText4; > > private Cursor flightCursor; > > @Override > protected void onCreate(Bundle savedInstanceState) { > // TODO Auto-generated method stub > super.onCreate(savedInstanceState); > setContentView(R.layout.flight_view); > > mRowId = savedInstanceState != null ? > savedInstanceState.getLong > (FlightDbAdapter.KEY_ROWID) : null; > > if (mRowId == null){ > Bundle extras = getIntent().getExtras(); > mRowId = extras != null ? extras.getLong > (FlightDbAdapter.KEY_ROWID) : null; > } > > flightno = (TextView) findViewById(R.id.viewFlightno2); > depCity = (TextView) findViewById(R.id.viewDepCity2); > depDate = (TextView) findViewById(R.id.viewDepDate2); > arrCity = (TextView) findViewById(R.id.viewArrCity2); > arrDate = (TextView) findViewById(R.id.viewArrDate2); > aircraft = (TextView) findViewById(R.id.viewAircraft2); > ticketno = (TextView) findViewById(R.id.viewTicketno2); > seat = (TextView) findViewById(R.id.viewSeat2); > reminder = (TextView) findViewById(R.id.viewReminder2); > > //FLIPPER > viewFlipper = (ViewFlipper) findViewById(R.id.flipper); > animationText1 = (TextView) > findViewById(R.id.animationTekst1); > animationText2 = (TextView) > findViewById(R.id.animationTekst2); > animationText3 = (TextView) > findViewById(R.id.animationTekst3); > animationText4 = (TextView) > findViewById(R.id.animationTekst4); > > flightDbAdapter = new FlightDbAdapter(this); > flightDbAdapter.open(); > > fillInText(); > } > > private void startFlightFlipper() { > viewFlipper.startFlipping(); > viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, > R.anim.push_left_in)); > viewFlipper.setOutAnimation(AnimationUtils.loadAnimation > (this,R.anim.push_left_out)); > > } > > @Override > protected void onResume() { > super.onResume(); > Cursor c = flightCursor; > fillInText(); > } > > private void fillInText() > { > if (mRowId != null) { > Cursor flight = flightDbAdapter.fetchFlight(mRowId); > startManagingCursor(flight); > flightno.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_FLIGHTNO))); > depCity.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_DEPARTURECITY))); > depDate.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_DEPARTUREDATE))); > arrCity.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_ARRCITY))); > arrDate.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_ARRDATE))); > aircraft.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_TICKETNO))); > ticketno.setText(flight.getString( > > flight.getColumnIndexOrThrow(flightDbAdapter.KEY_SEAT))); > seat.setText(flight.getString( > > flight.getColumnIndexOrThrow(flightDbAdapter.KEY_SEAT))); > //reminder.setText(flight.getInt(flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_REMINDER))); > > animationText1.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_FLIGHTNO))); > animationText2.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_DEPARTURECITY))); > animationText3.setText(flight.getString( > flight.getColumnIndexOrThrow > (flightDbAdapter.KEY_ARRCITY))); > > startFlightFlipper(); > } > } > > @Override > public boolean onCreateOptionsMenu(Menu menu) { > menu.add(0,DELETE_ID, 2, R.string.menu_delete).setIcon > (R.drawable.remove); > menu.add(1, UPDATE_ID, 3, R.string.menu_update).setIcon > (R.drawable.icon_edit); > menu.add(1, TRAVELPLANNER_HOME_ID, 1, "Travel Planner > Home").setIcon > (R.drawable.icon_home); > return super.onCreateOptionsMenu(menu); > } > > @Override > public boolean onOptionsItemSelected(MenuItem item) { > switch (item.getItemId()) { > case DELETE_ID: > deleteFlight(); > > break; > case UPDATE_ID: > finish(); > Intent intentUpdate = new Intent(this, > FlightEdit.class); > > intentUpdate.putExtra(flightDbAdapter.KEY_ROWID,mRowId); > startActivityForResult(intentUpdate, ACTIVITY_EDIT); > break; > case TRAVELPLANNER_HOME_ID: > /*Intent intentHome = new Intent(this, > TravelPlannerHome.class); > startActivity(intentHome);*/ > finish(); > default: > break; > } > return super.onOptionsItemSelected(item); > } > > private void deleteFlight() { > new AlertDialog.Builder(this) > .setTitle(R.string.delete_flight_title) > .setMessage(R.string.delete_flight) > .setPositiveButton(R.string.yes_button, new OnClickListener() { > public void onClick(DialogInterface dialog, int arg1) { > > flightDbAdapter.deleteFlight(mRowId); > Intent intent = new Intent (FlightView.this, > TravelPlannerHome.class); > startActivityForResult(intent, ACTIVITY_VIEW); > } > }).setNegativeButton(R.string.no_button, null).show(); > > } > > } > > On Mar 24, 10:12 pm, Wouter <wouterg...@gmail.com> wrote: > > > Ok.. > > > But what can i do with getItem like you said? > > > On Mar 24, 9:55 pm, Mark Murphy <mmur...@commonsware.com> wrote: > > > > If you cannot figure out how to use the SeparatedListAdapter, or where > > > it may need to be extended to help you achieve your ends, find some > > > other UI pattern you are more comfortable with. > > > > Wouter wrote: > > > > How? if i want to delete a item in my list what do i have to do with > > > > getItem? > > > > for example I have a delete option in my OptionsMenu: > > > > > This was my original code: > > > > public boolean onOptionsItemSelected(MenuItem item) { > > > > switch (item.getItemId()) { > > > > case DELETE_ID: > > > > > Cursor flightsCursor = flightDbHelper.fetchAllFlights(); > > > > long position = listView.getSelectedItemId(); > > > > flightsCursor.moveToPosition((int) position); > > > > flightDbHelper.deleteFlight(position); > > > > fillData(); > > > > > break; > > > > } > > > > > but now i have to detect which list it was so i have to delete it from > > > > my flight database or hotel database! > > > > How can i do that? > > > > > On Mar 24, 9:34 pm, Mark Murphy <mmur...@commonsware.com> wrote: > > > >> Wouter wrote: > > > >>> Ok i have integrated it now in my applications. It works now to show > > > >>> the 2 lists as one 1 list with seperated headers. > > > >>> But now, how can i determine which list is was, to integrate my > > > >>> seperated actions? > > > >>> I have a lists for flights and hotels (for example). When i click on a > > > >>> item in the flight list i have to open another activity then when I > > > >>> click on a item in the hotel list! > > > >> The same way you do with any list: call getItem() on the adapter. > > > > >> -- > > > >> Mark Murphy (a Commons Guy)http://commonsware.com > > > >> Android App Developer Training:http://commonsware.com/training.html > > > > -- > > > Mark Murphy (a Commons Guy)http://commonsware.com > > > Android App Developer Training:http://commonsware.com/training.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---