私はListView
に入れたデータを使ってデータベースを作成しました。プログラムによって作成されたため、このListView
を含むxmlファイルはありません。コード:ListViewを作成したデータベースを他のXMLに実装する方法ListViewを作成しましたか?
public class hornot extends Application{
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "persons_name";
public static final String KEY_HOTNESS = "persons_hotness";
public static final String DATABASE_NAME = "HotOrNotdb";
private static final String DATABASE_TABLE = "peopleTable";
private static final int DATABASE_VERSION = 1;
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);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_HOTNESS + " TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
}
public hornot(Context c) {
ourContext = c;
}
public hornot open() throws SQLException{ //ez a throws kell az SQLiteExample.java try részhez
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
これは私がListView
にアイテムを入れる方法です:
ListView lv;
ArrayList<String> todoItems = new ArrayList<String>();
ArrayList<String> todoItems2 = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, todoItems));
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
final hornot info = new hornot(this);
info.open();
Cursor c = info.getAllTitles();
if (c.moveToFirst())
{
do{
todoItems.add(c.getString(0) + " " + c.getString(1) + " " + c.getString(2));
}while (c.moveToNext());
}
if (todoItems.size() > 0)
{
lv.setAdapter(new ArrayAdapter<String>(sqview.this,android.R.layout.simple_list_item_1, todoItems));
}
私は、XMLを作成し、私は、プログラム(ID listplus
で別のListView
にListView
を作成つけたいのですが):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Button" android:id="@+id/b1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Button" android:id="@+id/b2"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<ListView android:id="@+id/listplus" android:layout_height="wrap_content"
android:layout_width="fill_parent"><;/ListView>
</LinearLayout>
どうすればいいですか?
1.なぜあなたの 'hornot'は' Application'を拡張していますか? 2.あなたはどこで 'listplus'というidを持つレイアウトを使っていますか?(別のアクティビティですか?) – Luksprog
@スルスキー1. hornot extendアプリケーションは間違いです、それはありません:) 2.はい、好きです別のアクティビティで使用することが可能です。 –
可能かどうかはわかりませんが、古いリストのように、すべてのメソッドが新しいリストビューで機能するようにしたいと思います。 –