-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCatGridAdapter.java
More file actions
75 lines (55 loc) · 1.88 KB
/
CatGridAdapter.java
File metadata and controls
75 lines (55 loc) · 1.88 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
package com.example.quizapp;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;
import java.util.Random;
public class CatGridAdapter extends BaseAdapter {
private List<CategoryModel> catList;
public CatGridAdapter(List<CategoryModel> catList) {
this.catList = catList;
}
@Override
public int getCount() {
return catList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View view;
if(convertView == null)
{
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cat_item_layout,parent,false);
}
else
{
view = convertView;
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SplashActivity.selected_cat_index = position;
Intent intent = new Intent(parent.getContext(),SetActivity.class);
intent.putExtra("Catagories ", position);
intent.putExtra("CAT_ID", position+1);
parent.getContext().startActivity(intent);
}
});
((TextView) view.findViewById(R.id.catName)).setText(catList.get(position).getName());
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(255),rnd.nextInt(255),rnd.nextInt(255));
view.setBackgroundColor(color);
return view;
}
}