0
私はlistviewの各項目に水平recylerviewを追加した垂直listviewを作成しました。私はrecylerviewの詳細を取得できますが、listviewの値を取得する方法はわかりません私はrecylerviewの特定の項目をクリックした。ここに私を助けて、私はまた、レイアウト - linkrecylerviewを持つlistviewの値を取得する
ListAdapterの私のスナップ貼り付けられています
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 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))
}
@Override
public LessonDataHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).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();
}
class LessonDataHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
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);
slipImage.setOnClickListener(this);
}
public void bindSlip(VideoList videoList) {
nameOfSlip.setText(videoList.stringSlipName);
slipImage.setImageResource(videoList.stringImage);
}
@Override
public void onClick(final View view) {
if (view.getId() == slipImage.getId()) {
// String s = String.valueOf(getAdapterPosition()+1);
String s1 = ((nameOfSlip).getText().toString());
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.abc_dialog_option_chapter);
dialog.setTitle("What Do You Want?");
TextView text = (TextView) dialog.findViewById(R.id.dialogLessonName);
text.setText("Lesson Name");
TextView text1 = (TextView) dialog.findViewById(R.id.dialogChapterName);
text1.setText(s1);
Button b1 = (Button) dialog.findViewById(R.id.dialogPlayVideo);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, YouTubePlayerActivity.class);
intent.putExtra("demoVideo", "oYaR9wyLiWs");
context.startActivity(intent);
}
});
Button b2 = (Button) dialog.findViewById(R.id.dialogPlayQuiz);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, QuizActivity.class);
context.startActivity(intent);
}
});
Button b3 = (Button) dialog.findViewById(R.id.dialogPlayCrossword);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, CrosswordActivity.class);
context.startActivity(intent);
}
});
dialog.show();
}
}
}
}
class VideoList {
public String stringSlipName;
public int stringImage;
public VideoList(String stringSlipName, int stringImage) {
this.stringImage = stringImage;
this.stringSlipName = stringSlipName;
}
}