Android 从单独类的数据库填充listview
我很难找到从数据库填充列表视图的方法 这是我的密码: SQLDatabase.java 这是我的listview类,基本上这是listview从数据库中分离出来的一个类 ListMovingNames.javaAndroid 从单独类的数据库填充listview,android,android-listview,android-sqlite,Android,Android Listview,Android Sqlite,我很难找到从数据库填充列表视图的方法 这是我的密码: SQLDatabase.java 这是我的listview类,基本上这是listview从数据库中分离出来的一个类 ListMovingNames.java 我要做的是填充列表视图,并在从列表中选择一项时执行特定任务。使用光标或适配器执行此操作。单击查看游标适配器的用法 好的,一种方法是定义用于存储数据库数据的变量,并在将数据填充到列表视图时使用此变量。这里我读取数据库并将变量存储在其他变量中 public List
我要做的是填充列表视图,并在从列表中选择一项时执行特定任务。使用光标或适配器执行此操作。单击查看游标适配器的用法
好的,一种方法是定义用于存储数据库数据的变量,并在将数据填充到列表视图时使用此变量。这里我读取数据库并将变量存储在其他变量中
public List<App_List> getAppList(String appclass){
List<App_List> App_ListView = new ArrayList<App_List>();
String AppTable_Name="favorite_apps";
String AppList_Query="SELECT * FROM " + AppTable_Name +" WHERE appclass = "+ "'"+appclass+"'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(AppList_Query, null);
if (cursor.moveToFirst()){
do{
App_List mAppList = new App_List();
if(cursor.getString(7).equalsIgnoreCase("local")){
// if application is from local server also take the version
mAppList.setVersion(cursor.getString(0));
}
mAppList.setApp_Name(cursor.getString(3));
mAppList.setApp_Description(cursor.getString(4));
mAppList.setApp_Link(cursor.getString(6));
mAppList.setPlace(cursor.getString(7));//place is added here
mAppList.setApp_Pkg(cursor.getString(1));
App_ListView.add(mAppList);
}while (cursor.moveToNext());
}
db.close();
return App_ListView;
在这里,我将数据填充到列表视图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View mView=convertView;
if (convertView == null)
mView = inflater.inflate(R.layout.app_adapter, parent,false);
App_List mAppList= mList.get(position);
((TextView) mView.findViewById(R.id.textView_appName)).setText(mAppList.getApp_Name());
((TextView) mView.findViewById(R.id.textView_appDescription)).setText(mAppList.getApp_Description());
public List<App_List> getAppList(String appclass){
List<App_List> App_ListView = new ArrayList<App_List>();
String AppTable_Name="favorite_apps";
String AppList_Query="SELECT * FROM " + AppTable_Name +" WHERE appclass = "+ "'"+appclass+"'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(AppList_Query, null);
if (cursor.moveToFirst()){
do{
App_List mAppList = new App_List();
if(cursor.getString(7).equalsIgnoreCase("local")){
// if application is from local server also take the version
mAppList.setVersion(cursor.getString(0));
}
mAppList.setApp_Name(cursor.getString(3));
mAppList.setApp_Description(cursor.getString(4));
mAppList.setApp_Link(cursor.getString(6));
mAppList.setPlace(cursor.getString(7));//place is added here
mAppList.setApp_Pkg(cursor.getString(1));
App_ListView.add(mAppList);
}while (cursor.moveToNext());
}
db.close();
return App_ListView;
public class App_List {
private String App_Name;
private String App_Description;
private String App_Link;
private String App_Pkg;
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
private String Version;
private String place;
public String getVersion() {
return Version;
}
public void setVersion(String version) {
Version = version;
}
public String getApp_Name() {
return App_Name;
}
public void setApp_Name(String app_Name) {
App_Name = app_Name;
}
public String getApp_Description() {
return App_Description;
}
public void setApp_Description(String app_Description) {
App_Description = app_Description;
}
public String getApp_Link() {
return App_Link;
}
public void setApp_Link(String app_Link) {
App_Link = app_Link;
}
public String getApp_Pkg() {
return App_Pkg;
}
public void setApp_Pkg(String app_Pkg) {
App_Pkg = app_Pkg;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View mView=convertView;
if (convertView == null)
mView = inflater.inflate(R.layout.app_adapter, parent,false);
App_List mAppList= mList.get(position);
((TextView) mView.findViewById(R.id.textView_appName)).setText(mAppList.getApp_Name());
((TextView) mView.findViewById(R.id.textView_appDescription)).setText(mAppList.getApp_Description());