- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个扩展自 BaseAdapter
用作自定义的类 Adapter
对于我的 ListView
.如果我使用 List<>
作为数据集,我在 getView()
中没有任何问题方法,一切正常 - 我的列表中填充了来自 List
的所有数据.但是如果我使用 HashMap
这永远行不通。据我了解getView()
遍历集合,这适用于 List
因为它是可迭代的。
private class MAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public MAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
v = mInflater.inflate(R.layout.list_item, null);
}
Task task = taskList.get(position); // works perfect if taskList is List and doesn't work if it is HashMap. What shell I do to use HashMap here?
if (task != null) {
TextView tvDescription = (TextView) v
.findViewById(R.id.task_text_view);
TextView tvTime = (TextView) v
.findViewById(R.id.time_text_view);
if (tvDescription != null) {
tvDescription.setText(task.getDescription());
}
if (tvTime != null) {
tvTime.setText(task.showTime());
}
}
return v;
}
最佳答案
你不能。 BaseAdapter 实现了 ListAdapter 并且它被称为 ListAdapter 是有原因的。为什么要使用 HashMap?
更新:
从列表中删除。
for(int j = list.size() - 1; j >= 0; j--){
Object o = list.get(j);
if(o.getId().equals(id)) {
list.remove(o); // find obj and remove
break;
}
}
adapter.notifyDataSetChanged(); // update ListView
或者同时保留列表和 HashMap。我建议只使用列表。
Object o = map.remove(id); // remove object by id
list.remove(o); // remvove object from list
adapter.notifyDataSetChanged(); // update ListView
关于android - 如果我使用 HashMap,我应该如何在 BaseAdapter getView() 中迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5237315/
好的,我一直在仔细搜索,但我在实现 BaseAdapter 时遇到了一些问题。 我已经能够实现一个简单的游标适配器 http://developer.android.com/resources/sam
我将使用下面的代码从服务器(URL)加载适配器的图像。它适用于新型移动设备。但是,旧模型会崩溃并返回“java.lang.OutOfMemoryError”。它将把 A 行或 B 行标记为错误。如何避
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我想在 ListView 中显示具有多列的数组。 调用 View.getView() 时出现此错误: android.widget.linerlayout cannot be cast to andr
嗨,我已经扩展了 BaseAdapter,我的列表大小是 20,但它只显示了 7 条记录,在第 7 条记录之后它又从 0 开始显示。 公共(public)类 ContactsAdapter 扩展 Ba
大家 最近在用ADT开发android 2.2的程序。程序在模拟器上运行正常,但在真机上运行却遇到了一个奇怪的问题。 我使用 BaseAdapter 创建一个 MenuAdapter,它将加载名为 V
这是我的自定义 BaseAdapter 的构造函数 public MyAdapterAds(Activity activity, BaseAdapter delegate) { this.ac
我有一个像这样的 JSON 数组:[{"usename":"user", "user_pic":"picture", "photo":"http://hfhfhfhhfh.jpg", "timesta
嗨,我是这个机器人的新手。我只是对基本适配器感到困惑。我的问题是考虑在一个数组中我有 10 个项目(从 0 到 9)。在 baseadapter 的 getview() 选项中,我在 textview
有没有办法通过 getApplicationContext() 获取 BaseAdapter 类中的 context? 我需要这个,因为我要从 url 加载图像。我在这里使用 context: 这是在
我有一个 ListView,它扩展了 BaseAdapter。我有一个数据 [] 数组。 ListView 正确膨胀和填充。我想要做的是在用户选择项目时以及是否选择了上一个项目时,使 ImageVie
无论如何,我正在努力制作的应用程序都有一个简单的列表和一个位于底部的按钮。我的问题是我的自定义 BaseAdapter 不显示元素。我知道,因为我的元素只是一个字符串,所以我可以使用 ArrayAda
我正在尝试将一个整数数组传递给一个 baseadapter,这样 A.class 就会将一个整数数组传递给 B.class 中的 BaseAdapter。以下是我在 A.Class(发件人)中传递整数
我在运行刚从 ADT(Eclipse) 转换而来的 android 项目时遇到此错误。 找到一个话题 here但没有回答。谁有解决办法? 最佳答案 这是解决方法。 类 XXXAdapter 扩展了 a
我正在使用 Android Studio 创建 Android 应用程序。我在使用自定义 SimpleAdapter 的 Activity 中有 ListView 。我需要在自定义适配器中使用自定义字
我使用了 ListView 。我有 5 件元素。当我启动程序时,我只看到 3. 处理程序,用于进度条开始处理 3/5 项目。我去看 4,5 项,所以我从 View 1,2 项中丢失了。 4 和 5 项
我有一个自定义BaseAdapter对于我的ListView我在其中实现 AdapterView.OnItemClickListener . 问题是onItemClick(AdapterView, V
在我的应用程序中,我遇到了与 here 相同的错误或here但是,建议的清理 Eclipse 项目的解决方案对我不起作用。具体来说,我有一个自定义 ListView 适配器,它尝试从其布局文件加载两个
我有一个 ListView 和一个将值附加到 View 的 Baseadapter 类。适配器类看到除一个之外的所有变量..我不知道该变量是否超出了类的范围..我已经检查过,但似乎找不到问题出在哪里
我刚刚构建了一个扩展 BaseAdapter 的新类。我相信我已经正确设置了所有内容,但是,当我尝试在 fragment 内设置适配器时,我想使用它,但出现以下错误: 构造函数 HomeBase(Ho
我是一名优秀的程序员,十分优秀!