小编Shi*_*tra的帖子

如何将Hashmap <String,List <Items >>扩展到Recyclerview中

我希望键的字符串必须作为标题,列表必须在该映射键下膨胀RecyclerView.

谢谢你的帮助

public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

private WeakHashMap<String, List<VideoItem>> mData = new WeakHashMap<>();
private ArrayList<String> mKeys;
ArrayList<WeakHashMap<String,List<VideoItem>>> hashMapArrayList;

public Adapter(WeakHashMap<String, List<VideoItem>> mData, ArrayList<WeakHashMap<String,List<VideoItem>>> hashMapArrayList) {
    this.mData = mData;
    this.hashMapArrayList=hashMapArrayList;
    mKeys = new ArrayList<String>(mData.keySet());
}

public String getKey(int position)
{
    return (String) mKeys.get(position);
}


@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.player_item, parent, false);
    MyViewHolder holder=new MyViewHolder(v);
    return holder;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    String key = getKey(position);
    WeakHashMap<String, List<VideoItem>> …
Run Code Online (Sandbox Code Playgroud)

android list hashmap android-recyclerview

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

Exoplayer 不播放视频仅播放音频

ExoPlayer不显示视频。我可以收听音频,但无法播放视频。我正在使用。ExoplayerRecyclerview只能看到黑屏并听到音频。我无法跟踪问题。我正在播放HLS中的视频ExoPlayer

android exoplayer android-recyclerview

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

在Recyclerview中删除页脚后的分隔符

有没有办法在一个页脚后删除分隔符Recyclerview.我正在使用项目装饰将分隔符添加到适配器.我在适配器中添加页脚.还在页脚下方显示页脚.我想删除它.

这是我的Divider代码

public class DividerItemDecoration extends RecyclerView.ItemDecoration {

private static final int[] ATTRS = new int[]{
        android.R.attr.listDivider
};

public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;

public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;

private Drawable mDivider;

private int mOrientation;

public DividerItemDecoration(Context context, int orientation) {
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);
    a.recycle();
    setOrientation(orientation);
}

public void setOrientation(int orientation) {
    if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
        throw new IllegalArgumentException("invalid orientation");
    }
    mOrientation = orientation;
} …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

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

如何使Recyclerview中的Clicked位置居中

我想将点击的位置居中Recyclerview.我可以滚动Recyclerview到某个位置,但我想在屏幕中间位置.我用这种方法滚动到那个位置.

videoRecyclerview.scrollToPosition(position);
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

6
推荐指数
4
解决办法
6638
查看次数

如何禁用和启用 recyclerview 滚动

我想在横向模式下禁用 recyclerview 滚动并在纵向模式下启用它。

 recyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            // Stop only scrolling.
            return rv.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING;
        }
    });
Run Code Online (Sandbox Code Playgroud)

我正在使用此方法禁用滚动,但找不到再次启用它的方法。

谢谢你的帮助!

android android-recyclerview

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

使用 Intent.createChooser 关闭活动

我正在使用Intent.createChooser共享内容。然后共享Intent.createChooser对话框出现并且工作正常,但是当我按后退按钮关闭对话框时,它完成了活动。我想阻止Activity关闭只是想关闭Intent.createChooser对话框。onclick 事件位于Recyclerview.

 shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //align the selection to the
                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_TEXT, items.get(position).getShareUrl());
                context.startActivity(Intent.createChooser(shareIntent, "Share with"));
            }
        });


<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

<supports-screens>
    android:resizeable="true"
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:xlargeScreens="true"
    android:anyDensity="true"
</supports-screens>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:hardwareAccelerated="true"
        android:largeHeap="true"
        android:launchMode="singleTop" …
Run Code Online (Sandbox Code Playgroud)

android android-activity

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