- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有加载程序的自定义游标适配器。我想在加载数据并使用 bindview 创建 View 后在 onLoadFinished() 中获取 View 对象,这样我就可以更改 EditText View 的属性(例如可见性)。但是 bindview 不返回对 View 对象的引用。
我可以只使用..
TextView myView = (TextView)this.findViewById(R.id.recipe_instructions);
在
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
dataAdapter.swapCursor(cursor);
dataAdapter.bindView(findViewById(R.id.recipe_name), this, cursor);
dataAdapter.bindView(findViewById(R.id.recipe_instructions), this, cursor);
TextView myView = (TextView)this.findViewById(R.id.recipe_instructions);
}
在这种情况下,我只是为每个 ID 创建 1 个 View ,但如果我创建了很多呢?我将如何获得对 View 对象的引用,以便我可以特别更改 1 的属性?
最佳答案
您的光标适配器必须像:
public class TodoCursorAdapter extends CursorAdapter {
public TodoCursorAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}
// The newView method is used to inflate a new view and return it,
// you don't bind any data to the view at this point.
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.item_todo, parent, false);
}
// The bindView method is used to bind all data to a given view
// such as setting the text on a TextView.
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Find fields to populate in inflated template
TextView tvBody = (TextView) view.findViewById(R.id.tvBody);
TextView tvPriority = (TextView) view.findViewById(R.id.tvPriority);
// Extract properties from cursor
String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
int priority = cursor.getInt(cursor.getColumnIndexOrThrow("priority"));
// Populate fields with extracted properties
tvBody.setText(body);
tvPriority.setText(String.valueOf(priority));
}
}
关于android - 使用bindview后如何获取 View 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31226440/
如何为具有绑定(bind) View 的适配器添加点击处理程序?刚刚开始。谢谢。 最佳答案 将其放入您的 binderView - 反正我为我工作。 public void bindView(View
我在使用 DeskClock 的一些代码时发现,当我尝试修改 CursorAdapter 时,每个项目都会调用 newView。 (我实际上想添加一个分隔线,看起来单独添加分隔线比将它们添加到单个 l
我已经受这个问题困扰好几个月了(但现在我正在调优)。但是,我现在迫切需要知道为什么我的适配器感觉有必要在一条记录上最多运行 4 次 bindView。 我有一个填充 GridView 的自定义光标适配
我试图在 ListView 中显示来自 Cursor 的信息,每行包含一个 ImageView 和一个 TextView。我有一个 CustomCursorAdapter 扩展 CursorAdapt
当覆盖 ArrayAdapter 时,我知道使用这样的模式是正确的: if(view != null){ ...create new view setting fields from data
实现时onLoadFinished() , 它需要 moveToFirst()运行良好,但为什么在实现 bindView() 时不需要这样做?对于 CursorAdapter ?以及何时使用它? on
对此可能有一个简单的答案,但尝试充分使用 Butterknife,将一些 findViewById 转换为 @BindViews,并注意到我无法在需要声明为 Final 的 View 上使用 Bind
我以前看过关于这个主题的主题:Android: Issue with newView and bindView in custom SimpleCursorAdapter仍然不明白我的代码有什么问题。
安卓工作室 2.3.3。 我的布局 xml 文件: 在我的app/build.gradle中: apply plugin: 'com.android.application' appl
如果可以的话,我会尽量具体 - 请耐心等待,第一次提问并且对这个平台上的编程相对较新。如果之前有人问过/回答过这个问题,我深表歉意 - 请将其链接给我。我上下搜索但发现了其他不相关的(至少对我而言)问
我目前正在编写一个应用程序,需要根据数据库中的条目在 ListView 中设置图像。 我直接在 customCursorAdapter 的 bindView() 方法中通过 switch-case 实
我正在开发一个带有 listView 的 Android 应用程序,并且正在对其进行优化。它在一个 Activity 中使用自定义游标适配器,我注意到 bindview() 为列表的每一行触发了两次。
我正在使用 Butterknife 绑定(bind) View 。当绑定(bind)多个 View 时喜欢Acting on Multiple Views In a List , @BindViews
我创建了一个扩展 CursorAdapter 的类,我在 bindView 方法上遇到问题。 @Override public void bindView(View v, Context contex
我正在学习 android,对此了解不多,但显然节省资源很重要,所以我想知道设置背景颜色的一种做法是否明显优于另一种: 对我来说,在“onCreateViewHolder”中设置 View 的背景颜色
我正在使用自定义 CursorAdapter(帖子)在 ListView 中显示数据。有些帖子没有评论(我想显示相关信息)并且数据在不同的游标中(我无法加入表格,因为我按帖子 ID 分组以防止 Lis
我制作了自定义的 SimpleCursorAdapter,这样当没有电话号码时我可以单击 ListView 中的按钮(按钮需要调用某人)我希望按钮不可见,起初我的代码正确显示所有内容但是当我向上滚动并
我试图在 CursorAdapter 中的 bindView 方法的匿名内部类中获取 FragmentActivity 引用。实际上,当在我的 ListView 中单击 ImageView 时,我试图
我正在创建一个 ListView ,它有两个 TextView 和一个自定义 View 作为选择指示器,以加载数据我正在使用 CursorAdapter 并覆盖 bindView 和 newView。
我试图在不使用 Butterknife 方法的情况下编写以下代码,主要用于学习目的。任何人都可以在没有使用的情况下帮助编写它吗? 我猜这是 TextView textName = findViewBy
我是一名优秀的程序员,十分优秀!