1
私はネットワークからrecyclerview経由でデータを表示しようとしていますが、logcatにエラーが見つかりました。レイアウトをスキップします。フラグメント上のRecyclerViewとCardView、レイアウトマネージャが接続されていません。レイアウトをスキップ
これは私のrecyclerviewコードです:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_utama, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.list_utra);
dataku = new ArrayList<>();
gridLayoutManager = new GridLayoutManager(getContext(), 4);
adapter = new RecyclerAdapter(getContext(), dataku);
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy){
if(gridLayoutManager.findLastCompletelyVisibleItemPosition() == dataku.size()-1){
Ambildatadariserver(dataku.get(dataku.size()-1).getId());
}
}
});
return view;
}
そして、これが私のRecyclerAdapterです:
public class RecyclerAdapter extends RecyclerView.Adapter <RecyclerAdapter.ViewHolder> {
private Context context;
private List<DataJson> datajson;
public RecyclerAdapter(Context context, List<DataJson>datajson){
this.context = context;
this.datajson = datajson;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View Itemview = LayoutInflater.from(parent.getContext()).inflate(R.layout.daftart_list, parent, false);
return new ViewHolder(Itemview);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.tvnama.setText(datajson.get(position).getNama());
holder.tvemail.setText(datajson.get(position).getEmail());
holder.tvtanggal.setText(datajson.get(position).getTanggal());
}
@Override
public int getItemCount() {
return datajson.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView tvnama, tvemail, tvtanggal;
public ViewHolder(View Itemview){
super(Itemview);
tvnama = (TextView) Itemview.findViewById(R.id.nama);
tvemail = (TextView) Itemview.findViewById(R.id.email);
tvtanggal = (TextView) Itemview.findViewById(R.id.tanggal);
}
}
}
マイフラグメントレイアウト:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/utamas"
tools:context="ptguwatirtasejahtera.utraposmobile.FragmentUtama"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/list_utra"/>
</RelativeLayout>
これはMyCardViewレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
android:layout_height="80dp">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="Nama: "
tools:text="Nama: "
android:id="@+id/nama"
/>
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/nama"
android:textSize="15dp"
android:text="Email: "
tools:text="Email: "
android:id="@+id/email"
android:layout_alignParentLeft="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tanggal"
android:layout_alignParentRight="true"
android:text="Tgl Lahir: "
android:textSize="15dp"
android:layout_marginTop="10dp"
android:layout_below="@id/nama"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
ヘルプ
私の問題を解決しますが、recyclerview何も表示されません。 –
また、 'dataku'リストにいくつかの項目を入れる必要があります。 –