小编Val*_*tin的帖子

OnClickListener不适用于GridView中的第一项

我在创建基于GridView的日历时遇到问题.这是网格:

GridView日历

这应该是一个填充了事件的日历,所以我有我的适配器实现OnClickListener,我为日历中的每个按钮设置了该监听器.它适用于每个按钮,除了第一个按钮(在本例中为30).当我单击它时不起作用,但是当我尝试单击第一个按钮后单击另一个按钮时,它会在执行另一个按钮的单击之前执行第一个按钮.

我已经扫描了大约10页的相关问题,但没有发现有人遇到这个问题.请帮忙!

如上所述,这是我的代码的getView函数:

    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;
        ViewHolder holder;
        if (row == null)
        {
            holder = new ViewHolder();
            LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.calendar_day_gridcell, parent, false);
            holder.gridCell = (Button) row.findViewById(R.id.calendar_day_gridcell);
            holder.multiDayEvent = (EventLengthView)row.findViewById(R.id.eventLengthView);
        }
        else{
            holder = (ViewHolder)row.getTag();
        }

        int calendarGridHeight = (calendarView.getHeight()-5)/(getCount()/7);
        AbsListView.LayoutParams params = new AbsListView.LayoutParams(
                android.view.ViewGroup.LayoutParams.FILL_PARENT,
                calendarGridHeight);
        row.setLayoutParams(params);

        //Change the background drawable depending on the position in the calendar
        if ((position+1) % 7 …
Run Code Online (Sandbox Code Playgroud)

android android-gridview

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

Android前置摄像头拍摄倒置照片

我有这个以纵向模式运行的应用程序,作为一个活动的一部分,我有一个相机对象作为片段运行.

我可以选择从前置摄像头切换到后置摄像头,使用后置摄像头拍照时一切都很好.

当我用前置摄像头拍照时,它们会被倒置180度.现在我知道这可能与纵向模式中的方向有关,但是在横向模式中使用它会破坏我的应用程序的想法.

无论如何这可以修复,所以拍摄的照片与您在预览中看到的相同吗?

        listener = new OrientationEventListener(this.getActivity(),SensorManager.SENSOR_DELAY_NORMAL){

        @Override
        public void onOrientationChanged(int orientation) {
            // TODO Auto-generated method stub
            if (orientation == ORIENTATION_UNKNOWN) return;
             android.hardware.Camera.CameraInfo info =
                    new android.hardware.Camera.CameraInfo();
             android.hardware.Camera.getCameraInfo(mCurrentCamera, info);
             orientation = (orientation + 45) / 90 * 90;
             int rotation = 0;
             if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                 rotation = (info.orientation - orientation + 360) % 360;
             } else {  // back-facing camera
                 rotation = (info.orientation + orientation) % 360;
             }
             if (mCamera.getParameters() != null){
             Camera.Parameters mParameters = mCamera.getParameters(); …
Run Code Online (Sandbox Code Playgroud)

camera android

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

Dagger 2 ContributesAndroidInjector为模块提供活动

我正试图找出一种不那么模板化的方法来实现ActivityModule我在所有应用程序活动中使用的方法.这是我目前的设置:

ActivityModule:

@Module
class ActivityModule(private val activity: Activity) {

    @Provides @ActivityScope
    fun providesActivity(): Activity = activity

    @Provides @ActivityContext @ActivityScope
    fun providesContext(): Context = activity

    @Provides @ActivityContext @ActivityScope
    fun providesLayoutInflater(): LayoutInflater = activity.layoutInflater

    @Provides @ActivityContext @ActivityScope
    fun providesResources(): Resources = activity.resources

}
Run Code Online (Sandbox Code Playgroud)

AppActivityModule(为AndroidInjectionModule提供活动)

@Module(subcomponents = [
        AppActivityModule.WelcomeActivityComponent::class
    ])
    internal abstract class AppActivityModule {

        @Binds 
        @IntoMap 
        @ActivityKey(WelcomeActivity::class)
        abstract fun bindWelcomeActivityInjectorFactory(builder: WelcomeActivityComponent.Builder): AndroidInjector.Factory<out Activity>

        @ActivityScope
        @Subcomponent(modules = [(ActivityModule::class)])
        interface WelcomeActivityComponent : AndroidInjector<WelcomeActivity> {
        @Subcomponent.Builder abstract class Builder : AndroidInjector.Builder<WelcomeActivity>() …
Run Code Online (Sandbox Code Playgroud)

java android kotlin dagger dagger-2

10
推荐指数
1
解决办法
1755
查看次数

Android Oreo字体系列NPE崩溃

我正在使用API 26中引入的新Android 字体支持,并在支持库的第26版中向后移植.

我创建了font_family.xml两种字体,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<font-family
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <font
        android:font="@font/regular_font"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/regular_font"
        app:fontStyle="normal"
        app:fontWeight="400"/>

    <font
        android:font="@font/bold_font"
        android:fontStyle="normal"
        android:fontWeight="700"
        app:font="@font/bold_font"
        app:fontStyle="normal"
        app:fontWeight="700"/>

</font-family>
Run Code Online (Sandbox Code Playgroud)

然后我在我的活动布局中将它设置在TextView上,如下所示:

<TextView
        style="@style/TextAppearance.Display1"
        android:layout_width="wrap_content"
        android:fontFamily="@font/font_family"
        android:textStyle="bold"
        android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

这可以在运行Marshmallow的Nexus 5上使用正确的字体呈现TextView(使用支持库).但是当我尝试在具有以下堆栈的Pixel Oreo设备上运行它时崩溃了:

Caused by: android.view.InflateException: Binary XML file line #44: Binary XML file line #44: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class TextView
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a …
Run Code Online (Sandbox Code Playgroud)

fonts android textview android-layout android-8.0-oreo

8
推荐指数
1
解决办法
688
查看次数

Android Fabric Crashlytics在初始化时找不到资源崩溃

我从谷歌播放控制台得到了这个报告 - 看起来Fabric在启动时崩溃,因为某些用户找不到资源:

java.lang.RuntimeException: 
  at android.app.ActivityThread.installProvider (ActivityThread.java:6423)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:6012)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:5951)
  at android.app.ActivityThread.-wrap3 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1710)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1496)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)

Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.ResourcesImpl.getResourcePackageName (ResourcesImpl.java:248)
  at android.content.res.Resources.getResourcePackageName (Resources.java:2785)
  at io.fabric.sdk.android.services.common.CommonUtils.getResourcePackageName (Unknown Source)
  at io.fabric.sdk.android.services.common.CommonUtils.getResourcesIdentifier (Unknown Source)
  at io.fabric.sdk.android.services.common.CommonUtils.getBooleanResourceValue (Unknown Source)
  at io.fabric.sdk.android.services.common.FirebaseInfo.isFirebaseCrashlyticsEnabled (Unknown Source)
  at com.crashlytics.android.CrashlyticsInitProvider.shouldInitializeFabric (Unknown Source)
  at com.crashlytics.android.CrashlyticsInitProvider.onCreate (Unknown Source)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1759)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1734)
  at android.app.ActivityThread.installProvider (ActivityThread.java:6420) …
Run Code Online (Sandbox Code Playgroud)

java android crashlytics

7
推荐指数
0
解决办法
401
查看次数

DirectCompute最佳numthreads设置

我最近一直在使用计算着色器,我正在尝试确定设置[numthreads(x,y,z)]和调度调用的最佳方法.我的演示窗口是800x600,我每像素启动1个线程.我正在进行2D纹理修改 - 没有太重.

我的第一次尝试是指定

[numthreads(32,32,1)]
Run Code Online (Sandbox Code Playgroud)

我的Dispatch()调用总是如此

Dispatch(ceil(screenWidth/numThreads.x),ceil(screenHeight/numThreads.y),1)
Run Code Online (Sandbox Code Playgroud)

因此,对于第一个实例

Dispatch(25,19,1)
Run Code Online (Sandbox Code Playgroud)

这个速度为25-26 fps.然后我减少到[numthreads(4,4,1)],运行速度为16 fps.将它增加到[numthreads(16,16,1)]开始了大约30 fps的良好结果.使用Y线程组编号[numthreads(16,8,1)]进行操作,设法将其推送到32 fps.

我的问题是有没有一种最佳的方法来确定线程数,这样我可以最有效地利用GPU,或者只是好的试验和错误?

directx direct3d directx-11 compute-shader directcompute

6
推荐指数
1
解决办法
2587
查看次数

Android持久底页初始可见性

我正在尝试在我的布局中实现一个持久的底页 - 一个不能完全隐藏,但总是从底部偷看,可以扩展到全高.这是我的布局:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">

        <!-- main content -->

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutBottomSheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center|bottom"
        android:background="@drawable/custom_background"
        android:clipToPadding="false"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        app:behavior_hideable="false"
        app:behavior_peekHeight="50dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <!-- bottom sheet content -->

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我期望发生的事情是,一旦我落在屏幕上,底部工作表就会被看到并折叠,但事实并非如此 - 它是隐藏的.我可以得到它通过调用展现出来bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED)onCreate().奇怪的是,这只会稍微扩大一点 - 超过指定的峰值高度但小于它应占用的全高度.在它出现在这种状态后,我可以将它上下拖动到它应该的位置,它工作正常.问题是屏幕上的初始着陆搞砸了.

我确信有一种方法可以使这个工作,所以底板最初出现在它的窥视高度.有任何想法吗?

android android-layout android-design-library bottom-sheet

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

一种无需阅读通知源即可将通知标记为可见的方法?

我的情况如下:我正在使用stream-js 库。我将某些事件的条目添加到用户的通知源中 - 评论、关注等。在写入他们的源后,我还会向该用户的设备发送推送通知。

如果用户单击推送通知,我希望能够将相应的活动标记为可见。目前无法做到这一点,因为 addaddToMany调用不会返回添加的活动的 ID 供我在通知负载中发送。

理想情况下,我想要一种方法来标记通知源项目,如活动组 ID 或其他唯一 ID(或 )所示foreignId。有没有办法做到这一点?如果不是,还有什么替代方案?

getstream-io

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