我有以下代码&希望arraylist中的所有数据都来自sqlite数据库
import android.app.Activity;
public DataSingleton() {
visibleSections = new ArrayList<>();
visibleSections.add("Who We Are");
visibleSections.add("What We Do");
visibleSections.add("How Can You Help");
visibleSections.add("Take a Look");
visibleSections.add("In The News");
visibleSections.add("Get In Touch");
}
}
答案 0 :(得分:2)
public static String query_select_all = "SELECT * FROM " + TABLENAME;
public ArrayList<model> DataSingleton()
{
ArrayList<visible_Model> visibleSections = new ArrayList<visible_Model>();
Cursor cursor = database_helper.rawQuery(query_select_all, null);
if (cursor.moveToFirst()) {
do {
visible_Model model = new visible_Model();
model.setMessage(cursor.getString(cursor
.getColumnIndex(COLUMN_FROM_MSG)));
visibleSections.add(model);
} while (cursor.moveToNext());
}
return visibleSections;
}
在这里,我在上面创建模型名称作为visile_model并使用setMessage方法。最后我将该模型添加到arraylist中 visibleSections