- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我很困惑。我在网上找到了一些建议,但我无法在此代码上实现它。这是我的问题。每次我滚动时, ListView 的顺序都会困惑。我不知道该怎么做。我真的需要一些帮助。我会非常感谢你的好意。这是我的代码:
public class ListViewAdapterMeasurement extends CursorAdapter {
TextView lblContent, lblDate;
DBHelper dbHelper;
Button btnSelect;
public ListViewAdapterMeasurement(Context context, Cursor c) {
super(context, c, FLAG_REGISTER_CONTENT_OBSERVER);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.details_feed, parent, false);
lblContent = (TextView) view.findViewById(R.id.lblContent);
lblDate = (TextView) view.findViewById(R.id.lblDate);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
View convertView = view;
if (convertView == null)
{
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.details_feed, null);
}
dbHelper = new DBHelper(getApplicationContext());
int intContentIndex = cursor.getColumnIndex((Tables.FeedTable.COLUMN_CONTENT));
String strContentIndex = cursor.getString(intContentIndex);
int intDateIndex = cursor.getColumnIndex((Tables.FeedTable.COLUMN_DATE));
String strDateIndex = cursor.getString(intDateIndex);
lblContent.setText(strContentIndex);
lblDate.setText(strDateIndex);
}
}
最佳答案
在 Android 中, View 可以多次使用,这意味着来自“newView”的已经实例化的 View 可以在“bindView”中使用不止一次。要清楚:“newView”并不经常被调用(<=)比“绑定(bind) View ”。因此,在“newView”中保存状态不是你能做的。在“newView”中,您只能操作计算从该适配器实例化的所有 View 的属性,这些 View 在“bindView”中未被操作。每个单行(或项目)的所有动态值都已在“bindView”中设置,因为可以(并且将会)出现重用 View 。在您的适配器中保存行(或项目)的单个内部 View 会导致意外行为并且无法完成。这是你的问题。当“view-object-pool”中没有已经实例化和空闲(未显示/可回收)的 View 时,将调用“newView”。此外,您还必须考虑重置“bindView”中的某些 subview ,以防此处出现已填充的 View ,并且在特殊情况下某些行/项目的属性保持未设置状态。最后:您无法知道在“bindView”中给定的 View 是新建的还是回收的。希望清楚的东西。快乐编码
关于java - ListViewAdapter extends CursorAdapter 滚动时顺序困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37908453/
这段代码: interface I {} public class Test { TableView table; Test(ObservableList list) {
我们从 .NET 2.0 升级到 .NET 3.5。我的一位同事尝试在 Visual Studio 2008 中的调试器下运行 ASP .NET Web 项目时出现以下对话框。他可以正常构建,但无法调
我有一个具有class User extends Authenticatable的用户模型类,并且我也创建了另一个具有class Foo extends Model的模型类 这会在显示路线文件中的数据
我遇到的一个常见问题 @extend当试图用另一个 @extend 覆盖继承的属性时. 这是一个例子: // class selectors to be @extended // these coul
我对以下代码的 typescript 编译错误感到困惑: function f(x: T, y: S) { if (x === y) { // ERROR: This condition
这与对象 {} === {} 无关, found this issues不知道这个是不是一样 类型集 - AUnion 不是空集。另外两种类型(L 和R)正在扩展它。我的理解是这些 L、R 至少和 A
我收到以下错误: Extender Provider failed to return an Extender for this object 尝试为 .Net v4.7.2 加载 WCF 项目时。我
我收到以下错误: Extender Provider failed to return an Extender for this object 尝试为 .Net v4.7.2 加载 WCF 项目时。我
我刚刚在读Javascript: Module Pattern vs Constructor/Prototype pattern?我很好奇,当我们使用 $.fn.extend 或 $.extend 扩
我正在用 extend 做一些测试,在我做了一些观察后我有点困惑。初步观察: console.log($.extend === $.fn.extend); // trure // and since
我一直在使用一些通用方法从元素的可变参数创建集合,例如 public Set createSet( T... elements ) { ... 然而,最近我遇到了编译器没有按照我的预期去做的情况。以
刚去面试,问了一个问题。 面试官 - Java 是否支持多重继承? 我 - 不 面试官 - Java 中的每个类都扩展了类 Object(类 Object 除外),如果我们从外部扩展一个类,例如 Cl
我目前正在实现我的第一个 GWT 应用程序,我只是有一个快速的问题,关于在创建复杂的自定义小部件时 Extends Composite 和 Extend a specified widget 之间的区
使用 Observable 扩展 Object 和应用于以下类的扩展 Observable 之间有什么区别。 当应用程序运行时,结果是一样的。 library models; import 'pack
我制作了一个类装饰器,我想限制这个装饰器只能应用于某些类,所以我这样做了: @decorator() class A { foo:string; } @decorator() class B
在这个例子中: import java.util.*; public class Example { static void doesntCompile(Map> map) {} st
注意:这个问题与 Enum 无关,所以它不是重复的。Enum 被迫只与自身比较,因为编译器生成类型参数,而不是因为 java 递归类型参数。 我试图找到将类声明为的优势: public class S
我是 Java 的新手,正在尝试从 Java 泛型和集合一书中理解以下奇怪的语法。(我广泛使用 C++ 模板,因此可以声称了解泛型编程的基础知识和可能的陷阱): interface Collect
注意:这个问题与 Enum 无关,所以它不是重复的。Enum 被迫只与自身比较,因为编译器生成类型参数,而不是因为 java 递归类型参数。 我试图找到将类声明为的优势: public class S
有人知道是否可以延长 child Blade 吗? 我的应用程序有一个通用的布局模板,然后每个页面都从该模板@extends。每个页面都可以根据需要为其他 HTML block (例如模态)引入一系列
我是一名优秀的程序员,十分优秀!