Ini harus dihapus.
Intent launchActivity = new Intent(MainActivityPlanes.this, MainActivityChampagne.class);
startActivity(launchActivity);
Dan Anda memiliki ini
public class MainActivityChampagne
MainActivityChampagne
Your Anda kelas tidak memperpanjang aktivitas. Ini adalah kelas non aktivitas.
Untuk menyetel data ke tampilan daftar.
MainActivityChampagne db = new MainActivityChampagne(MainActivityPlanes.this);
db.open();
ArrayList<String> list = db.getData();
Sekarang gunakan daftar untuk menyetel data ke tampilan daftar.
Tentukan row.xml dengan tampilan teks dengan id 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);
Setelah Anda menyetel adaptor ke tampilan daftar.
List.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> listView, View itemView, int itemPosition, long itemId)
{
. // on list item click do what is necessary
}
});
Sunting:
baris.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>
Bidikan jepret
Sunting2:Pembaruan telah diperbaiki. Namun Anda perlu memodifikasi di bawah ini sesuai dengan kebutuhan Anda.
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);
}
}