- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个Service
我的应用程序中的类,我必须使用 FirebaseListAdapter<String>
就在其中。
这是MyService.java
文件:
public class MyService extends Service {
DatabaseReference firebaseDatabaseRef;
String followedBy;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
firebaseDatabaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https://***-***.firebaseio.com/");
Toast.makeText(getBaseContext(), "Service started", Toast.LENGTH_SHORT).show();
FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(this,
String.class, android.R.layout.simple_expandable_list_item_1, firebaseDatabaseRef) {
@Override
protected void populateView(View v, String model, int position) {
followedBy = model.substring(30);
}
};
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(getBaseContext(), "Service stopped", Toast.LENGTH_SHORT).show();
}
}
但无法编译,因为我收到此错误:
Error:(133, 47) error: no suitable constructor found for FirebaseListAdapter(MyService,Class<String>,int,DatabaseReference)
constructor FirebaseListAdapter.FirebaseListAdapter(Activity,Class<String>,int,Query) is not applicable
(argument mismatch; MyService cannot be converted to Activity)
constructor FirebaseListAdapter.FirebaseListAdapter(Activity,Class<String>,int,DatabaseReference) is not applicable
(argument mismatch; MyService cannot be converted to Activity)
我应该用什么来代替 this
在 FirebaseListAdapter<String>
成功编译并运行我的代码?
请告诉我。
最佳答案
Activity 是提供用户界面的应用程序组件。 Service 的文档解释:
A Service is an application component that can perform long-running operations in the background, and it does not provide a user interface
FirebaseListAdapter支持显示 Firebase 数据库中的数据。它在 Activity
中使用。它不能在服务
中使用。无需在 Service
中使用它,因为 Services 没有用户界面(除了可选的通知之外)。
关于java - 如何在服务中使用 FirebaseListAdapter<String>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41082501/
这个问题已经有答案了: Firebase List Adapter Constructor error (1 个回答) 已关闭 5 年前。 如何正确插入 FirebaseListAdapter?我总是
我正在遵循本指南: https://firebase.google.com/support/guides/firebase-android 我已经升级了除命令 FirebaseListAdapter
我正在尝试使用 FirebaseListAdapter 将 Firebase 存储目录中的图像填充到 GridView。 我有一个简单的 griditem.xml 布局: 进入我的 Activi
在我的 Android 应用程序中,我有一个 ListView 和一个显示我的用户的 FirebaseListAdapter,现在我希望 firebaseListAdapter 按字母顺序排序。我怎样
尝试为我的 ListView 创建 FirebaseListAdapter 时发现问题,我想从 Firebase 实时数据库填充它。Android Studio 说 Cannot resolve sy
我正在使用 FirebaseListAdapter,我需要显示 ProgressDialog,但我不知道如何知道它何时完成加载。 public class TabFragment1 exten
是否可以指定 FirebaseListAdapter 读取哪些数据? 目前,我只能读取完整的数据库。数据库包含许多不同的对象。该对象有一个值,表示创建该对象的用户。 现在,我只想读取这个特殊用户的对象
我正在将 FirebaseListAdapter 用于 ListView,它工作得很好。我还有一个额外的要求,即显示 ListView 中存在的元素数量。我该怎么做? 我通读了 FirebaseLis
我有一个Service我的应用程序中的类,我必须使用 FirebaseListAdapter就在其中。 这是MyService.java文件: public class MyService e
我有一个结构如下的 Firebase 数据库 根 - 用户 -用户名1 -年龄:30 -email_address : xxx@yyy.com -用户连接 -用户名2:N -用户名3:是 -用户名4:
我正在使用 FirebaseListAdapter 并覆盖所需的 onPopulateView 方法以从实时数据库收集数据,然后将适配器设置为 UI 中的 ListView: mMessageSumm
我来这里是为了询问是否有人知道我无法解决的问题的解决方法。 基本上,我正在使用 Firebase 在 Android 中编写一个简单的聊天应用程序作为练习。我在主布局中使用 ListView ,并在每
我目前有一个 FirebaseListAdapter,它用最后 5 个项目填充 ListView: @Override public void onViewCreated(View view, Bun
我正在开发一个安卓群聊应用程序,基于我在 envatotuts+ 上找到的教程,除了 FirebaseListAdapter 之外,一切看起来都很好.该项目拒绝编译,它给出了这个错误 Error:(1
此代码获取值并在 ListView 中设置它们我也想获取 key 以使用它们,请查看图像以查看数据库示例 FirebaseListAdapter firebaseListAdapter = new F
我正在制作一个使用 Cloud Firebase 的 Android 聊天应用。在用消息填充 ListView 时,我想使用两种布局,一种用于传入消息,一种用于传出消息。当遵循执行类似操作的教程时,
我有一个连接到 Firebase 的 Android 应用程序,我正在使用 FirebaseListAdapter 使用数据库引用中的数据填充自定义布局。 这正在按预期工作。但是是否可以查询此数据以仅
这个问题已经困扰我一段时间了。我以前从未真正使用过 ListViews,也没有使用过 FirebaseListAdapters。我想做的就是通过显示 id 和用户位置来启动列表的基础,但由于某种原因,
我无法让 FirebaseListAdapter 工作,我的 ListView 在 fragment 中始终为空。可能是什么问题? 这是我的数据库: 我的 PirmadienisFragment .x
所以我想在 Firebase API 的帮助下制作一个聊天应用程序,但似乎我无法在特定项目的布局之间更改(例如:发送和接收的消息)。我找到了一种方法,但效率不高,这种方法是这样的:我为发送和接收消息的
我是一名优秀的程序员,十分优秀!