Това трябва да бъде премахнато.
Intent launchActivity = new Intent(MainActivityPlanes.this, MainActivityChampagne.class);
startActivity(launchActivity);
И вие имате това
public class MainActivityChampagne
Вашето MainActivityChampagne
клас не разширява дейността. Това е неактивен клас.
За да настроите данните за изглед на списък.
MainActivityChampagne db = new MainActivityChampagne(MainActivityPlanes.this);
db.open();
ArrayList<String> list = db.getData();
Сега използвайте списъка, за да настроите данните на изглед на списък.
Дефинирайте row.xml с текстов изглед с идентификатор textView1.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivityPlanes.this, R.layout.row, R.id.textView1,list);
List = (ListView) findViewById(R.id.listView1);
List.setAdapter(adapter);
След като настроите адаптера на изглед на списък.
List.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> listView, View itemView, int itemPosition, long itemId)
{
. // on list item click do what is necessary
}
});
Редактиране:
row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="114dp"
android:layout_marginTop="30dp"
android:text="TextView" />
</RelativeLayout>
Моментална снимка
Редактиране 2:Актуализацията е фиксирана. Все пак трябва да промените по-долу според нуждите си.
public class MainActivityChampagne {
public static final String KEY_NAME = "title";
public static final String KEY_NOTES = "lastcall";
private static final String DATABASE_NAME = "Champagnedb5";
private static final String DATABASE_TABLE = "champagneTable";
private static final int DATABASE_VERSION = 1;
private static final String KEY_ID = "id";
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub\
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
KEY_NAME + " TEXT NOT NULL," +
KEY_NOTES + " TEXT NOT NULL" + ");"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXIST " + DATABASE_TABLE);
onCreate(db);
}
}
public MainActivityChampagne(Context c){
ourContext = c;
}
public MainActivityChampagne open(){
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
ourHelper.close();
}
public long createEntry(String titles, String notes) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, titles);
cv.put(KEY_NOTES, notes);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
public ArrayList<String> getData() {
//TODO Auto-generated method stub
String[] columns = new String[] { KEY_NAME };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
String result = "";
int iNotes = c.getColumnIndex(KEY_NAME);
ArrayList<String> string_array = new ArrayList<String>();
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
result = c.getString (iNotes) + "\n";
string_array.add(result);
}
return string_array;
}
public void updateEntry(String thetitles, String thenotes) {
// TODO Auto-generated method stub
ContentValues cvUpdate = new ContentValues();
cvUpdate.put(KEY_NAME, thetitles);
cvUpdate.put(KEY_NOTES, thenotes);
ourDatabase.update(DATABASE_TABLE, cvUpdate, "id "+"="+1, null);
// this will update row 1 coz id is 1.
//ourDatabase.update(DATABASE_TABLE, cvUpdate, KEY_NAME + "=" + thetitles + KEY_NOTES + "=" + thenotes, null);
}
}