0
嗨我對android開發相當新,我想問如果它是可以找到並查看數據庫,如果它創建如下?代碼工作正常,通過添加查看記錄,但問題是我無法找到數據庫。Android如何查找數據庫及其表格?
public class db extends Activity
{
SQLiteDatabase mydb;
TextView name,review;
Button save,myview;
ListView lv;
ArrayList data;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.db);
name=(TextView)findViewById(R.id.entername);
save=(Button) findViewById(R.id.bsave);
review = (TextView)findViewById(R.id.enterreview);
lv=(ListView) findViewById(R.id.list);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
Toast.makeText(getApplicationContext(), data.get(arg2).toString(),3000).show();
}
});
mydb = db.this.openOrCreateDatabase("mydatabase", MODE_PRIVATE, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS test2 (id INTEGER PRIMARY KEY AUTOINCREMENT,name
varchar,review varchar);");
//=== SAVE BUTTON FOR INSERTING DATA TO DATABASE =======
save.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mydb.execSQL("insert into test2 (name,review) values(?,?);", new String[]
{name.getText().toString(), review.getText().toString(), });
Toast.makeText(getApplicationContext(), "DATA INSERTED", 3000).show();
}
});
myview=(Button)findViewById(R.id.bview);
data=new ArrayList();
//=VIEW BUTTON TO SHOW DATA INSERTED IN THE LISTVIEW=======
myview.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getApplicationContext(), "Review Added", 5000).show();
Cursor cursor2=mydb.rawQuery("SELECT * FROM test2;", null);
if (cursor2.moveToFirst())
{
Toast.makeText(getApplicationContext(), "Review's are:", 5000).show();
data.clear();
do
{
data.add(cursor2.getString(cursor2.getColumnIndex("name")));
data.add(cursor2.getString(cursor2.getColumnIndex("review")));
}
while (cursor2.moveToNext());
//====CODE FOR SHOWING DATA AS A SIMPLE LIST ITEM=========================================
ArrayAdapter <String> adapter=new ArrayAdapter<String>
(db.this,android.R.layout.simple_list_item_1,data);
lv.setAdapter(adapter);
}
else
{
Toast.makeText(getApplicationContext(), "There are no reviews available", 3000).show();
}
cursor2.close();
}
});
}
}
你是一個Linux操作系統的窗口在linux上machine..if我可以張貼,從您的device..if拉數據庫中的簡單的shell腳本你喜歡。 –
嘿謝謝你的repoly,但我使用windows 8。 – user3449550
請參閱http://stackoverflow.com/questions/4856210/access-sqlite-database-on-android-device – laalto