-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyAdapter.java
More file actions
84 lines (70 loc) · 2.79 KB
/
Copy pathMyAdapter.java
File metadata and controls
84 lines (70 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.example.trip_packer.adapter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.trip_packer.CheckList;
import com.example.trip_packer.R;
import com.example.trip_packer.WeatherService;
import com.example.trip_packer.constants.myconstants;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
List<String> titles;
List<Integer> images;
LayoutInflater inflater;
Activity activity;
public MyAdapter(Context context, List<String> titles, List<Integer> images, Activity activity) {
this.activity = activity;
this.titles = titles;
this.images = images;
this.inflater = LayoutInflater.from(context);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.main_item, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.title.setText(titles.get(position));
holder.img.setImageResource(images.get(position));
holder.linearLayout.setAlpha(0.8F);
holder.linearLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent;
if (myconstants.WEATHER_CAMEL_CASE.equals(titles.get(position))) {
intent = new Intent(view.getContext(), WeatherService.class);
} else {
intent = new Intent(view.getContext(), CheckList.class);
intent.putExtra(myconstants.HEADER_SMALL, titles.get(position));
intent.putExtra(myconstants.SHOW_SMALL, myconstants.MY_SELECTIONS.equals(titles.get(position)) ? myconstants.FALSE_STRING : myconstants.TRUE_STRING);
}
view.getContext().startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return titles.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
TextView title;
ImageView img;
LinearLayout linearLayout;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
img = itemView.findViewById(R.id.img);
linearLayout = itemView.findViewById(R.id.linearlayout);
}
}
}