このようなリストビューでは、recylerviewを作成しましたimage recylerviewにはcardviewがあり、listviewにはテキストの配列が含まれています。私はアダプタでonclicklistnerを設定しましたが、私はクリックして、私は私の作るログをチェックしたが、それは表示されませんでした。リストビューに置かれたRecylerviewのListnerのOnclick listner
リサイクラービューコード:
public class LessonVideoAdapter extends RecyclerView.Adapter<LessonVideoAdapter.LessonDataHolder> {
private List<VideoList> slipList;
public LessonVideoAdapter() {
slipList = new ArrayList<>();
slipList.add(new VideoList("Chapter 1", R.drawable.demo_one));
slipList.add(new VideoList("Chapter 2", R.drawable.demo_two));
slipList.add(new VideoList("Chapter 3", R.drawable.demo_one));
slipList.add(new VideoList("Chapter 4", R.drawable.demo_two));
slipList.add(new VideoList("Chapter 5", R.drawable.demo_one));
slipList.add(new VideoList("Chapter 6", R.drawable.demo_two));
slipList.add(new VideoList("Chapter 7", R.drawable.demo_one));
slipList.add(new VideoList("Chapter 8", R.drawable.demo_two));
slipList.add(new VideoList("Chapter 9", R.drawable.demo_one));
slipList.add(new VideoList("Chapter 10", R.drawable.demo_two));
}
@Override
public LessonDataHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.abc_card_view_video, parent, false);
return new LessonDataHolder(view);
}
@Override
public void onBindViewHolder(LessonDataHolder holder, int position) {
VideoList s = slipList.get(position);
holder.bindSlip(s);
}
@Override
public int getItemCount() {
return slipList.size();
}
public class LessonDataHolder extends RecyclerView.ViewHolder {
public BlurLayout samplelayout;
private TextView nameOfSlip;
private ImageView slipImage;
private Context context;
public LessonDataHolder(View itemView) {
super(itemView);
// context = itemView.getContext();
nameOfSlip = (TextView) itemView.findViewById(R.id.demoText);
slipImage = (ImageView) itemView.findViewById(R.id.imageViewDemoVideo);
itemView.setClickable(true);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
{
Log.d("ashu", " clicked ");
}
}
});
}
public void bindSlip(VideoList videoList) {
nameOfSlip.setText(videoList.stringSlipName);
slipImage.setImageResource(videoList.stringImage);
}
}
public class VideoList {
public String stringSlipName;
public int stringImage;
public VideoList(String stringSlipName, int stringImage) {
this.stringImage = stringImage;
this.stringSlipName = stringSlipName;
}
}
}
リストビューコード:
public class ListAdapter extends BaseAdapter {
private Context context;
private String[] names={"Lesson 1: Intro","Lesson 2: Addition","Lesson 3: Subtraction","Lesson 4: Multiplication","Lesson 5: Geometry","Lesson 6: Shapes","Lesson 7: Quad","Lesson 8: Fun","Lesson 9: Problems-1","Lesson 10: Problems-2"};
LayoutInflater layoutInflater;
LessonVideoAdapter recyclerAdapter;
public ListAdapter(Context context) {
this.context = context;
layoutInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
recyclerAdapter=new LessonVideoAdapter();
}
@Override
public int getCount() {
return names.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View view1=layoutInflater.inflate(R.layout.abc_lesson_name,null,false);
TextView tittle=(TextView)view1.findViewById(R.id.lesson_name);
tittle.setText(names[i]);
RecyclerView recyclerView=(RecyclerView)view1.findViewById(R.id.recyclerViewChapters);
recyclerView.setAdapter(recyclerAdapter);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false);
recyclerView.setLayoutManager(linearLayoutManager);
return view1;
}
活動:
public class SubjectActivity extends AppCompatActivity {
private ListView listview_lesson;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subject);
listview_lesson = (ListView) findViewById(R.id.listview_lesson);
listview_lesson.setAdapter(new ListAdapter(this));
}
}
ルSSON名のxml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="230dp"
android:paddingTop="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="3dp"
app:cardBackgroundColor="#b7a2d6"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/lesson_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="LessonName"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewChapters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lesson_name" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
abc_cardview_demoは:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.daimajia.androidviewhover.BlurLayout
android:id="@+id/blur_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cardViewDemo1"
android:layout_width="220dp"
android:layout_height="180dp"
android:layout_margin="5dp"
android:elevation="5dp"
app:cardBackgroundColor="#e4a455"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:weightSum="1">
<FrameLayout
android:id="@+id/frameDemoOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".2">
<ImageView
android:id="@+id/imageViewDemoVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="3dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="3dp"
android:scaleType="fitXY"
android:src="@drawable/demo_one" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/cardview_border" />
</FrameLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_weight=".8"
app:cardBackgroundColor="#e9e6e3"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/demoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="DEMOVIDEOONE"
android:textColor="#c9750f"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v7.widget.CardView>
</com.daimajia.androidviewhover.BlurLayout>
</RelativeLayout>
何かによると? –
'abc_card_view_video'と' abc_lesson_name'のコードを見ることができますか? –
@MayurRaval私は自分のコードplzを貼り付けました – Abhishek