【发布时间】:2014-01-25 18:48:32
【问题描述】:
我想将我的Sqlite 数据显示到我的ListView 中,但我做不到。
现在它可以显示Toast,但我怎样才能将它运行到我的ListView?
谢谢。
public class fehrest extends Activity {
public String fonts="BNazanin.ttf";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// DATABASE START
DBAdapter db = new DBAdapter(this);
try {
String destPath = "/data/data/" + getPackageName() + "/databases";
File f = new File(destPath);
if (!f.exists()) {
f.mkdirs();
f.createNewFile();
//---copy the db from the assets folder into
// the databases folder---
CopyDB(getBaseContext().getAssets().open("mydb"),
new FileOutputStream(destPath + "/MyDB"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//---get all contacts---
db.open();
Cursor c = db.getAllContacts();
if (c.moveToFirst()) {
do {
DisplayContact(c);
} while (c.moveToNext());
}
db.close();
//DATABASE END
setFace();
//Tab2 contents
}
//DATABASE COPY FILES
public void CopyDB(InputStream inputStream,
OutputStream outputStream) throws IOException {
//---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
// DATABASE COPY FILES END
// DATABASE SHOW INFO
public void DisplayContact(Cursor c) {
Toast.makeText(this,
"id: " + c.getString(0) + "\n" +
"Name: " + c.getString(1) + "\n" +
"Email: " + c.getString(2),
Toast.LENGTH_LONG).show();
}
// DATABASE SHOW INFO END
【问题讨论】:
-
阅读安卓记事本教程
-
您尝试过我帖子中的建议吗?有用吗??
-
对不起,但它不起作用
标签: android sqlite android-listview