小编joe*_*joe的帖子

如何为分析添加Firebase自定义事件?

我已经看到有关firebase分析的自定义事件的一些问题和答案,但我只是想问你一个直接的问题,所以你可以给我一个直接的答案:)

所以,这是我记录的方法:

@Override
public void logFeatureSelectedEvent(String categoryName, String actionName, String labelName) {
    Bundle bundle = new Bundle();
    bundle.putString(EventTrackingKeys.EventTypes.CATEGORY, categoryName);
    bundle.putString(EventTrackingKeys.EventTypes.ACTION, actionName);
    bundle.putString(EventTrackingKeys.EventTypes.LABEL, labelName);
    mFirebaseAnalytics.logEvent(EventTrackingKeys.EventAnalyticTypes.FEATURE_SELECTED_EVENT, bundle);
}
Run Code Online (Sandbox Code Playgroud)

使用自定义事件/键名称:

String CATEGORY = "category";
String ACTION = "action";
String LABEL = "label";
String FEATURE_SELECTED_EVENT = "feature_selected_event";
Run Code Online (Sandbox Code Playgroud)

因此,在我的firebase控制台中,我只获得事件名称"feature_selected_event",没有自定义参数名称.我已经看到一些答案,我应该调用setUserProperty()方法并在Firebase Analytics的"用户属性"选项卡中注册该用户属性.这是实现该方法的正确方法吗?:

   @Override
public void logFeatureSelectedEvent(String categoryName, String actionName, long value) {
    Bundle bundle = new Bundle();
    bundle.putString(EventTrackingKeys.EventTypes.CATEGORY, categoryName);
    bundle.putString(EventTrackingKeys.EventTypes.ACTION, actionName);
    bundle.putLong(EventTrackingKeys.EventTypes.VALUE, value);
    mFirebaseAnalytics.setUserProperty(EventTrackingKeys.EventTypes.CATEGORY, categoryName);
    mFirebaseAnalytics.setUserProperty(EventTrackingKeys.EventTypes.ACTION, actionName);
    mFirebaseAnalytics.setUserProperty(EventTrackingKeys.EventTypes.VALUE, value);
    mFirebaseAnalytics.logEvent(EventTrackingKeys.EventAnalyticTypes.FEATURE_SELECTED_EVENT, bundle);
}
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-analytics firebase-console

21
推荐指数
5
解决办法
3万
查看次数

在 RecyclerView Adapter notifyDataSetChanged() 之后未调用 onBindViewHolder

我正在从 Firebase 数据库获取一些数据,并尝试RecyclerView用它填充适配器。notifyDataSetChanged()调用适配器后,屏幕闪烁并且没有任何反应,我什至无法在 onBindViewHolder 中捕获断点。

这是我的代码:

POJO类:

public class Result2 implements Serializable {

private int score;
private String userName;

public Result2(int score, String userName) {
    this.score = score;
    this.userName = userName;
}

public int getScore() {
    return score;
}


public String getUserName() {
    return userName;
}
Run Code Online (Sandbox Code Playgroud)

}

这是我的活动布局,名为 activity_results.xml,其中包含 RecyclerView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="horizontal"
    android:weightSum="2">

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="USERNAME"
        android:textColor="#000"
        android:textSize="16sp"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="SCORE"
        android:textColor="#000"
        android:textSize="16sp"/> …
Run Code Online (Sandbox Code Playgroud)

android firebase android-recyclerview firebase-realtime-database

7
推荐指数
1
解决办法
3812
查看次数

RecyclerView网格布局管理器不会使项目居中

在此处输入图片说明

我继承了一个带有大量旧代码的大型项目,现在我遇到了一些奇怪的问题。

我需要使此屏幕具有带有网格布局管理器的recyclerview(2列)。这就是我得到的。有没有办法将这些图标放在屏幕中间?我试过重力,但无济于事。可能所有旧代码中都存在问题,或者仅仅是recyclerView的问题?

这是项目的布局(糟糕,请不要问..)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_view_controller_item_background"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textViewSceneKK"
        android:layout_width="match_parent"
        android:layout_height="@dimen/room_button_height"
        android:layout_gravity="center"
        android:layout_marginLeft="@dimen/row_filter_text_margin_left"
        android:layout_marginRight="@dimen/row_filter_text_margin_left"
        android:gravity="center"
        android:shadowDx="-1"
        android:shadowDy="-1"
        android:shadowRadius="1"
        android:textSize="@dimen/row_scene_kk_text_size" />

    <TextView
        android:id="@+id/textViewSceneName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/row_filter_text_margin_bottom"
        android:layout_marginLeft="@dimen/row_filter_text_margin_left"
        android:layout_marginRight="@dimen/row_filter_text_margin_left"
        android:layout_marginTop="@dimen/row_filter_text_margin_top"
        android:clickable="false"
        android:gravity="center"
        android:longClickable="false"
        android:textColor="@color/main_text_color"
        android:textSize="@dimen/row_browser_right_name_text_size" />
</LinearLayout>

<!--<View-->
<!--android:id="@+id/filterView"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:clickable="false"-->
<!--android:longClickable="false" />-->

<View
    android:id="@+id/filterViewClick"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:selectableItemBackground"
    android:focusable="false"
    android:focusableInTouchMode="false" />
Run Code Online (Sandbox Code Playgroud)

而不是布局:

<customview.CustomRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
Run Code Online (Sandbox Code Playgroud)

和代码:

 customRecyclerView.setHasFixedSize(false);
    customRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
    customRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
            R.drawable.line_separator_empty, DividerItemDecoration.VERTICAL_LIST));

customRecyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

CustomRecyclerView.java

public class CustomRecyclerView extends RecyclerView …
Run Code Online (Sandbox Code Playgroud)

android gridlayoutmanager android-recyclerview

5
推荐指数
1
解决办法
7208
查看次数

如何根据口味自动更改绘图?

我正在开发一个非常混乱的应用程序,并且是第一次使用口味。应用程序有 4,5 种口味,全部具有相同的背景颜色、绘图等。只有徽标不同。

现在我必须制作一种布局完全不同的新口味。背景颜色应该是黄色而不是灰色,可绘制图像应该是黑色而不是白色。问题是,我有大约 100 张不同的白色图像。有什么办法可以自动将它们更改为黑色吗?(设计者可以将它们重新绘制为黑色,我可以将它们放入该风格的可绘制文件夹中)或者我必须以编程方式检查是否使用了新风格,然后在每个使用白色可绘制的小部件上调用 setDrawable(newBlackImage) ?这似乎是一种非常复杂的方法,因为所有可绘制对象都是通过 XML 布局设置的。

他们使用flavor的方式是创建资源bool文件,然后检查代码是否某个键的值为true/false,然后隐藏/显示一些东西......所以我认为我应该做类似的事情,或者不?

这就是我的一种风格的项目结构:

在此输入图像描述

如您所见,每种口味只有不同的启动器和登录屏幕图标。此外,每个都有自己的数组、布尔值和字符串资源文件。但它们都共享相同的布局资源和带有白色图标的绘图。

android android-productflavors android-build-flavors android-flavors

4
推荐指数
1
解决办法
3999
查看次数

Dagger 2无法解析符号'DaggerAppComponent'

我正在尝试使用改装2,匕首2和MVP来创建一个简单的应用程序,但是我很难依赖,实际上,这是我尝试重建项目后得到的错误错误:任务执行失败':app:compileDebugJavaWithJavac ".

java.lang.StackOverflowError的

以及我提供AppComponent的App类:无法解析符号'DaggerAppComponent'

我将尝试向您展示我的项目是什么样的,这样有人可以看到问题,第一个是我的AppModule,其中包括PresentationModule.class

@Module(includes = PresentationModule.class)
public class AppModule {
    private App app;

    public AppModule(App app) {
        this.app = app;
    }

    @Provides
    @Singleton
    public App provideApp() {
        return app;
    }
}
Run Code Online (Sandbox Code Playgroud)

演示模块如下所示:

@Module(includes = InteractorModule.class)
public class PresentationModule {

    @Provides
    JokePresenter providePresenter(JokeInteractor jokeInteractor) {
        return new JokePresenterImpl(jokeInteractor);
    }
}
Run Code Online (Sandbox Code Playgroud)

和InteractorModule:

@Module(includes = {NetworkModule.class, PresentationModule.class})
public class InteractorModule {

    @Provides
    JokeInteractor provideJokeInteractor(RetrofitService service, JokePresenter presenter) {
        return new JokeInteractorImpl(service, presenter);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是JokePresenter,它具有对视图和交互器的引用:

public class JokePresenterImpl implements JokePresenter { …
Run Code Online (Sandbox Code Playgroud)

mvp android dependency-injection dagger-2

3
推荐指数
1
解决办法
8467
查看次数

如何从数组列表中提取某些子串之间的不同子串?

我不确定如何正确地提出这个问题,但希望这个例子可以解决问题.

我有一个字符串列表,例如("AS3K 4455 NJNSADN 4455 KLMDSMF043J 4455 NKFDG 4455 KMMFDG")

如你所见,有"4455"重复.我会有很长的叮咬列表,让我们说4455将代表我想要提取的消息的开头/结尾.我不是实现这一目标的最佳方式,所以如果有人遇到类似的问题,请停止:)

java string arraylist

2
推荐指数
1
解决办法
62
查看次数

如何在LG智能电视上安装Android应用?

我的USB上有android app apk,我把它插入我的LG智能电视,它显示我的USB设备,但apk不可见...任何想法有什么问题吗?

android lg smart-tv android-tv

1
推荐指数
1
解决办法
9万
查看次数

如何正确设置改造参数

我正在尝试使用Retrofit 2创建Weather应用程序,现在我很难正确设置呼叫.

这是正在运行的URL:

http://api.openweathermap.org/data/2.5/weather?q=London&APPID=MY_API_KEY
Run Code Online (Sandbox Code Playgroud)

所以,我有我的API密钥和BASE URL是:http://api.openweathermap.org ..这是我的Retrofit服务中的方法:

    @GET("/data/2.5/weather?q={city}/&APPID={api}")
    Observable<WeatherResponse> getWeather(@Path("city") String city, @Path("api") String api);
Run Code Online (Sandbox Code Playgroud)

而我得到的错误是:

java.lang.IllegalArgumentException:URL查询字符串"q = {city} /&APPID = {api}"必须没有替换块.对于动态查询参数,请使用@Query.

所以我试着这样:

@GET("/data/2.5/weather?{city}/&APPID={api}")
Observable<WeatherResponse> getWeather(@Query("city") String city, @Path("api") String api);
Run Code Online (Sandbox Code Playgroud)

我得到同样的错误......任何人都知道这里的交易是什么,我的网址有什么问题?

android android-developer-api retrofit2 rx-java2

0
推荐指数
1
解决办法
1677
查看次数