私はプログラム的CardView
を作成してrecyclerView
とcardView
を作成しようとしていますが、ここに私のコードでプログラムCardViewが表示されていない私は、メインクラスのXML
RecyclerViewは、
onCreate
を使用することを教えてください
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.lesson_layout, container, false);
ExampleRecyclerView = (RecyclerView) rootView.findViewById(R.id.ExampleRecyclerView);
List<ViewExample> exampleList = new ArrayList<>();
Log.i("dddddd", String.valueOf(exampleList));
//alos the list just show [] in the Logs
adapter = new ExampleAdapter(this, exampleList);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setSmoothScrollbarEnabled(true);
ExampleRecyclerView.setScrollbarFadingEnabled(true);
ExampleRecyclerView.setLayoutManager(llm);
ExampleRecyclerView.setAdapter(adapter);
return rootView;
}
ViewExample
クラス
public class ViewExample {
private String StepHeader, Code, Explanation;
public ViewExample(String stepHeader, String code, String explanation) {
StepHeader = stepHeader;
Code = code;
Explanation = explanation;
}
Getters & Setters are here...
}
そしてAdapter
public class ExampleAdapter extends RecyclerView.Adapter<ExampleAdapter.ExampleHolder> {
CardView ExampleCV;
List<ViewExample> exampleList;
ViewLesson viewLesson;
public ExampleAdapter(ViewLesson viewLesson, List<ViewExample> exampleList) {
this.viewLesson = viewLesson;
this.exampleList = exampleList;
}
public class ExampleHolder extends RecyclerView.ViewHolder { // here is where you define what text have value
LinearLayout parentL;
public ExampleHolder(View itemView) {
super(itemView);
parentL = new LinearLayout(parentL.getContext());
ExampleCV = new CardView(ExampleCV.getContext());
ExampleCV.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
parentL.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
parentL.setOrientation(LinearLayout.VERTICAL);
ExampleCV.addView(parentL);
}
}
@Override
public ExampleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ExampleHolder(ExampleCV);
}
@Override
public void onBindViewHolder(final ExampleHolder holder, int position) {
TextView tv = null;
final TextView finalTv = tv;
RootRef.child("Development").child("Level 2").child("Intent").child("Putextra").child("Examples")
.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.i("isa 5air", String.valueOf(dataSnapshot.getValue()));
finalTv.setText(String.valueOf(dataSnapshot.getValue()));
holder.parentL.addView(finalTv);
adapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
@Override
public int getItemCount() {
return 0;
}
}
編集 NB:私は、私はそれはあなたが使用することができます
しかし、私はより多くを追加するためにリサイクルビューを作成したいですあらかじめ良いものを持っている方 –