- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我的编程知识很薄,几天前我发现了 Java 和 Android SDK。
我有一个 SQLiteDatabase、一个 SQLiteOpenHelper 和一个正常工作的 Cursor(意味着我认为我了解如何使用 SQLiteOpenHelper 创建/打开数据库,在我的数据库上进行查询并获取游标)
目前,我将 i + labName + labCity 包装到一个结果字符串中,并显示到一个 TextView R.id.label 中
是否可以将 labName 绑定(bind)到 R.id.label,并将 labCity 绑定(bind)到另一个 TextView R.id.label2?
这是我需要帮助的 ListActivity 的代码:
public class MainLabList extends ListActivity implements OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_lab_list);
// DB
GestionDB gdb = new GestionDB(this, GestionDB.DATABASE_NAME, null, GestionDB.DATABASE_VERSION);
SQLiteDatabase theDB = gdb.getWritableDatabase();
// Cursor
String[] columns = {GestionDB.LAB_NAME, GestionDB.LAB_ADDRESS_CITY};
Cursor c =
theDB.query(GestionDB.TABLE_NAME, columns, null, null, null, null, null);
////////
this.setTitle(" " + c.getCount() + " Labs in Local Database");
ArrayList<String> results = new ArrayList<String>();
int i = 0;
c.moveToFirst();
/* Loop through all Results */
do {
i++;
String labName = c.getString(c.getColumnIndex(GestionDB.LAB_NAME));
String labCity = c.getString(c.getColumnIndex(GestionDB.LAB_ADDRESS_CITY));
/* Add current Entry to results. */
results.add("" + i + ": " + labName
+ " (" + labCity + ")");
} while (c.moveToNext());
//need rework
ListView lvLabListing = (ListView) findViewById(android.R.id.list);
ArrayAdapter<String> labListAdapter = new ArrayAdapter<String>(this,
R.layout.listing, R.id.label, results );
lvLabListing.setAdapter(labListAdapter);
lvLabListing.setOnItemClickListener(this);
//
// don't forget to close the database
gdb.close();
还有我想修改的 listing.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"></ImageView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/label"></TextView>
</LinearLayout>
我的 GestionDB 类很简单,如果数据库不存在,只需定义一些列,以及一些变量。
最佳答案
为此,您应该使用 CursorAdapter
,也许是 SimpleCursorAdapter
。 Here is an example .
关于android - 使用 ListAdapter/SQLite 数据库的初学者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2077900/
我正在实现 AdapterView产生一个AbsListView -like 类,我可以使用 CursorAdapter在布局中。我正在实现这个,因为我想使用方便的自动数据更新行为 CursorAda
Try to focus on general "dos and donts" regarding lists, e.g. is adding and removing 30 items of a 2
我有一个listadapter,其中有很多listitems,每个项目都包含一个textview 和一个imageview。我想从后端下载图片( 以 Base64 编码 ),所以 Picasso 和通
我对 Android 还很陌生,目前在使用自定义列表适配器时遇到一些问题。 基本上,我想制作一个问题列表,每个问题都有不同的类型(单选、复选框、文本、数字)。当 ListView 生成时,它显示得很好
我需要在另一个线程中加载自定义 ListAdapter 吗?我之前已经这样做过,但我也在同一个线程中下载了数据。 使用或不使用线程加载 ListAdapter 有何优缺点?加载线程是否需要大量资源?
我刚刚开始开发 Android,但遇到了问题。我有一个 DrawerNavigationListAdapter 和一个 DrawerNavigationListView,并且工作正常,现在我尝试向其中
我有一个 ListAdapter,用于在 Listview 中显示列表。现在我添加了一个长按菜单操作来删除任何选定的项目。 public boolean onContextItemSelected(M
加载列表适配器的最佳方式是什么。简单的问题,但我已经知道你们中的大多数人会说什么。你会说使用 LoaderManager/CursorManager。每个人都会告诉我它使用起来多么容易,而且它不能在
我已经有一个使用 SQLite 数据库和列表适配器的应用程序。我正在尝试更新我的应用程序以使用全文搜索功能,但正在努力寻找问题的答案。基本上,当我使用必要的 _id 列创建虚拟表时,数据库会将其转换为
我使用这个例子中的 ListAdapter: http://code.google.com/p/au-optimizing-layouts-201/source/browse/au_optimizin
在 ListAdapter 中,如何将数据添加到现有列表?submitList()只会用新列表替换现有列表, 也许一种更新数据的方法是这样的 adapter.addNewItem(list) 最佳答案
我在 RecyclerView 中遇到了分页无限滚动的问题,我正在使用 .addAll() 添加所有新项目 movieList.addAll(it.movieList) adapter.submi
我正在使用 Android Room和 Rx Flowable更新 RecyclerView将对象从我的数据库中。为了获得更好的动画和性能,我更新了项目以使用新的 ListAdapter在我的项目中。
我正在尝试将我的 Adapter 转换为 ListAdapter,以便将来包含 Paging 库。我的应用程序是一个基本的 2 fragment 笔记应用程序,第一个 fragment 具有回收器 V
我正在设置一个 RecyclerView,它使用 ListAdapter 来计算更改时的动画。 RecyclerView 通过 ViewModel 接收数据,ViewModel 通过 Firebase
我正在尝试使用 JSON 数据源中的项目列表填充 View 。我似乎无法让适配器在我的列表中显示 JSON 数据。这就是我到目前为止所做的。 MainActivity.java package com
我看了http://developer.android.com/reference/android/widget/ListAdapter.html并看到 ListAdapter 是一个公共(publi
我正在尝试获取 HashMap 的 ArrayList,以尝试获取可用的 ListAdapter。当我运行这个时,我得到一个 java.lang.RuntimeException: Your cont
好吧,所以我创建了一个 ListView 和我自己的 ListAdapter,但是每当我将结果添加到 ListAdapter 时,它都会崩溃,并显示 NullPointerException 当 fi
我有一个包含多个字段的类,我只想在 ListView 中显示其中一个字段 class FOO { String f1; String f2; String f3; }; FOO fo
我是一名优秀的程序员,十分优秀!