Android 在文本视图中显示sqlite数据库和XML文件中的数据
我想从XML资源在表中插入新行 我想在第一个活动中动态打印按钮,按钮的数量取决于表中的行数 例如:Android 在文本视图中显示sqlite数据库和XML文件中的数据,android,android-intent,android-sqlite,Android,Android Intent,Android Sqlite,我想从XML资源在表中插入新行 我想在第一个活动中动态打印按钮,按钮的数量取决于表中的行数 例如: TABLE_NAME = "languages" row1: LANGUAGE_NAME = "english", LANGUAGE_DESCRIPTION = "Some words in english" row2: LANGUAGE_NAME = "italian", LANGUAGE_DESCRIPTION = "Some words in italian" 我想显示两个按钮 当我点击
TABLE_NAME = "languages"
row1: LANGUAGE_NAME = "english", LANGUAGE_DESCRIPTION = "Some words in english"
row2: LANGUAGE_NAME = "italian", LANGUAGE_DESCRIPTION = "Some words in italian"
我想显示两个按钮
当我点击显示“英语”的按钮时,我想在second_活动的文本视图中看到的只是“一些英语单词”
上个月我尝试了很多,但总是失败
请帮帮我 简单:
查询您的数据库,从请求中获取字段数,获取数据,然后您可以使用listView来放大按钮。您必须通过解析XML文件来获取数据,然后将数据持久保存到sqlite数据库中,然后从数据库中获取数据并在应用程序中使用它 这是一种从XML解析数据的方法 这是一个在android上使用sqlite数据库的方法 希望它能帮助你
DatabaseHandler;
DatabaseHandler dh;
SQLiteDatabase db;
ArrayList<String>= lang_descrip;
db = dh.getReadableDatabase();
Cursor cursor = db.rawQuery(
"SELECT * FROM "+TABLE_NAME +"WHERE "+LANGUAGE_NAME+"=english", null);
if (cursor != null)
for(int i=0;i<=cursor.getCount();i++){
cursor.moveToFirst();
lang_descrip.add(cursor.getString(1));
//if you have 2nd column as description
}
//now u can use lang_descrip to get the size of it and create the number of buttons based on size
int size=lang_descrip.size();
//now you can use for loop for creating number of buttons with setting its text from lang_descrip's values
for(int i=0;i<size;i++)
{
Button myButton = new Button(this);
myButton.setText(lang_descrip.get(i).toString());
LinearLayout layout = (LinearLayout)findViewById(R.id.myLayout);
LayoutParams layParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
layout.addView(myButton, layParam);
}
sqlitedb数据库;
ArrayList=lang_descripp;
db=dh.getReadableDatabase();
Cursor=db.rawQuery(
“从“+表格名称+”中选择*,其中“+语言名称+”=英语”,空);
如果(光标!=null)
对于(int i=0;我感谢您,但我想在新活动中在按钮中显示语言名称,在文本视图中显示语言描述。我太难理解您的想法。对不起