来自https://developer.android.com/preview/material/ui-widgets.html
当我们创建时,RecyclerView.Adapter
我们必须指定ViewHolder
将与适配器绑定.
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private String[] mDataset;
public MyAdapter(String[] myDataset) {
mDataset = myDataset;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTextView;
public ViewHolder(TextView v) {
super(v);
mTextView = v;
}
}
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.some_layout, parent, false);
//findViewById...
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mTextView.setText(mDataset[position]);
}
@Override
public int …
Run Code Online (Sandbox Code Playgroud) 在RecyclerView
,我想设置一个空视图,以便在适配器为空时显示.有相同的ListView.setEmptyView()
吗?
我正在尝试制作一个有色的空视图占用RecyclerView之后的剩余空间.我看过不同的StackOverflow解决方案,但没有任何效果.基本上我想要这样的东西:
________________________
| |
| |
| |
| Recycler view |
| |
| ------------------- |
| colored empty view |
| |
| |
| |
| |
| |
_________________________
It should shrink as the RecyclerView grows.
________________________
| |
| |
| |
| Recycler view |
| |
| |
| |
| |
| |
| ------------------- |
| colored empty view |
| |
| |
_________________________
Run Code Online (Sandbox Code Playgroud)
但是,如果RecyclerView超过一个屏幕的价值,则应该没有空视图.这是我到目前为止所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud) @IntDefs
还是@StringDefs
在 Kotlin 中使用?当我将 Kotlin Enum 类反编译为 Java 类时,底层仍然使用了 Java Enum,不建议在 Android 开发中使用,这让我想到了这一点。
我正在尝试制作一个应用程序,在其中使用Recycle View和Volley从服务器获取数据,并且还使用了Navigation抽屉和片段,一切正常,但是当在recycle-view上没有数据时,我想显示一个通知,例如“没有数据!”我多次搜索互联网,但没有找到合适的解决方案,或者因为我完全是初学者,所以无法正确理解。
波纹管是我的Java文件
1.适配器
package com.eworld.myapplication;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.squareup.picasso.Picasso;
import java.util.List;
public class ExchangesAdapter extends RecyclerView.Adapter<ExchangesViewHolder> {
private List<ExchangesSetterGetter>exchangeList;
private Context context;
public ExchangesAdapter(List<ExchangesSetterGetter> exchangeList, Context context) {
this.exchangeList = exchangeList;
this.context = context;
}
@NonNull
@Override
public ExchangesViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardlayout,viewGroup,false);
ExchangesViewHolder viewHolder=new ExchangesViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull ExchangesViewHolder exchangesViewHolder, int i) {
String status="";
final ExchangesSetterGetter exchangesPosition=exchangeList.get(i);
if (exchangesPosition.getStatus().equals("1")) …
Run Code Online (Sandbox Code Playgroud)