Sorry for the stupid question, but this has been really confusing to me. I’m making a planner app, and I want the first screen to show a list of Itineraries pulled from a database(but maybe an array would work better?). I need the user to be able to add and delete them as they desire(via a menu button)A, and I want them to show two lines of text.
After clicking on the itinerary, it just should the user to a calendar-like page showing the various events that they’ve created, which will also be pulled from a database. If I can get it figured out for the main screen, I can likely figure it out again. I’m just having a bit of trouble figuring it all out. I’ve read the documentation and all that. It’s just going a bit over my head. I’ve never so much as shaken a stick at a database before.
TL;DR:
I need to create a user editable database(or array) that will be displayed in a ListView. How do I create and manage the database, and how do I get the contents to appear nicely in a ListView?
Thank you everyone!
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void addEvent(View view) {
}
}
/menu/activity_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/menu_settings"/>
<item
android:showAsAction="always|withText"
android:title="@string/add_event"
android:icon="@drawable/newcontent" />
</menu>
/layout/activity_main.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ListView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
</ListView>
Most of the information is found in the android developer resources, but its hard to know what to look for if you haven’t done it before. You can create a SQLite database and the interface to load data from the tables using a ContentProvider. Then use a CursorLoader to a asynchronously load the relevant records to populate your views. To change between the different pages try creating them as separate fragments which you can then change programmatically from the appropriate event handlers.