小编Hay*_*yan的帖子

findFirstVisibleItemPosition() 在nestedScrollView 中返回 0

我有一个recyclerView内幕nestedScrollView。我知道这是一个不好的做法,但有些情况我只能用这种方式处理。

<androidx.core.widget.NestedScrollView
    android:id="@+id/nestedScroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            tools:itemCount="1"
            tools:listitem="@layout/item_favorite_tournament"
            tools:visibility="visible" />

</androidx.core.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

这是我的代码。我将向您展示滚动部分,我需要在其中获取firstVisibleItemPosition. 但它返回0。

private void initList(RecyclerView recycler, View labelNoResults) {
    recycler.setAdapter(mAdapter);
    recycler.setHasFixedSize(true);
    mListLayoutManager = Objects.requireNonNull((LinearLayoutManager) recycler.getLayoutManager());


    recycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            final int p = mListLayoutManager.findFirstVisibleItemPosition();
            Log.d("Tag_1", "Position: " + p);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

我认为问题是因为nestedScrollView. 那么我怎样才能获得visibleItemPosition表单呢recyclerView?谢谢。

java android android-recyclerview android-nestedscrollview

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

Glide 不从 url 加载图像

我有ListView,我有ImageView。我需要从 url 获取图像并显示在 中ImageView,但这不起作用,图像不可见。在那ListView我有一个TextViewCheckBox太,但你并不需要它,因为这作品。我正在使用Glide. 所以有什么问题?

我设置了滑动占位符并加载了占位符。我已经完成调试,我看到 glide 获取了图像 URL。但是图片加载不出来。

好的,这是项目代码。

public class LanguageItem {

String imagePath;

LanguageItem(String imagePath,) {
    this.imagePath = imagePath;
}

public String getImagePath() {
    return imagePath;
}
Run Code Online (Sandbox Code Playgroud)

也有 textView 和 checkbox,但我没有向您展示,因为这很好用。

这里是适配器。

public class LanguageAdapter extends BaseAdapter {

private Context context;
private LayoutInflater lInflater;
private ArrayList<LanguageItem> objects;

LanguageAdapter(Context context, ArrayList<LanguageItem> itemObj) {
    this.context = context;
    objects = itemObj;
    lInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE); …
Run Code Online (Sandbox Code Playgroud)

java android android-glide retrofit2

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

改造是否对被破坏的碎片提出要求?

我使用翻新,并且有2个片段(片段A,片段B)。在每个片段中,我有2个请求(对于片段A,该请求称为请求A1,requestA2)。因此,我打开了我的应用程序并打开了片段A。在此之后,异步启动了请求A1和请求A2。因此,在此之后,我将打开Fragment B,并继续进行请求。(请求B1和B2)。但是,如果我打开片段B,然后快速单击“后退”按钮返回片段A,那么请求B1和B2是否会继续异步工作?还是改装会自动取消碎片销毁的请求?所以我需要在背面印刷机上写这样的东西吗?

if(call != null) {
  call.cancel();
}
Run Code Online (Sandbox Code Playgroud)

performance android request android-fragments retrofit

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

android deeplinking - 第一个路径前缀是动态的,但第二个不是

我有一个网址,例如https://www.mobilePhoneSystem.com/{user}/registerDate/{date}。所以{user}路径前缀是动态的。我只需要处理包含registerDate. 我在清单中写了这样的内容

<!-- Deep linking-->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:scheme="https"
                android:host="/www.mobilePhoneSystem.com"
                android:pathPrefix="/registerDate" />

        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

但它不会触发。当我在 mainfest 中添加任何用户时,例如pathPrefix=/user111/registerDate,它会触发并正常工作。但用户是动态的。那么我该如何处理这种类型的深层链接呢?

android manifest deep-linking intentfilter

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

StateFlow 设置值会删除一些事件,但更新不会

在我的应用程序中,我有一个 UIState 密封类来表示 UI 状态。

sealed class UIState<T> {
    class ShowLoading<T> : UIState<T>()
    class HideLoading<T> : UIState<T>()
    class ShowEmptyData<T> : UIState<T>()
    class ShowData<T>(val data: T) : UIState<T>()
    class ShowError<T>(val errorUIState: ErrorUIState) : UIState<T>()
}
Run Code Online (Sandbox Code Playgroud)

因此,我的viewmodel代码是:

 someRequest.apply { response ->
     when (response) {
         is ApiResponse.Success -> {
             _uiStateFlow.value = (UIState.HideLoading()) // First, hide the loading
             // Do some work
             _uiStateFlow.value = (UIState.ShowData(data))
         }
         is ApiResponse.Error -> {
             _uiStateFlow.value = (UIState.ShowError(error))
         }
     }
 }
Run Code Online (Sandbox Code Playgroud)

在这种情况下,大多数时候我的hideLoading状态不会收集,它会下降,因为成功/错误状态在 hideLoading 之后立即出现,而我的 UI …

android kotlin kotlin-coroutines

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