forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyAdapter.java
More file actions
71 lines (51 loc) · 2 KB
/
MyAdapter.java
File metadata and controls
71 lines (51 loc) · 2 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
package com.xxmassdeveloper.mpchartexample.notimportant;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import androidx.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.xxmassdeveloper.mpchartexample.R;
import java.util.List;
/**
* Created by Philipp Jahoda on 07/12/15.
*/
class MyAdapter extends ArrayAdapter<ContentItem> {
private final Typeface mTypeFaceLight;
private final Typeface mTypeFaceRegular;
MyAdapter(Context context, List<ContentItem> objects) {
super(context, 0, objects);
mTypeFaceLight = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
mTypeFaceRegular = Typeface.createFromAsset(context.getAssets(), "OpenSans-Regular.ttf");
}
@SuppressLint("InflateParams")
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ContentItem c = getItem(position);
ViewHolder holder;
holder = new ViewHolder();
if (c != null && c.isSection) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_section, null);
} else {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
}
holder.tvName = convertView.findViewById(R.id.tvName);
holder.tvDesc = convertView.findViewById(R.id.tvDesc);
convertView.setTag(holder);
if (c != null && c.isSection)
holder.tvName.setTypeface(mTypeFaceRegular);
else
holder.tvName.setTypeface(mTypeFaceLight);
holder.tvDesc.setTypeface(mTypeFaceLight);
holder.tvName.setText(c != null ? c.name : null);
holder.tvDesc.setText(c != null ? c.desc : null);
return convertView;
}
private class ViewHolder {
TextView tvName, tvDesc;
}
}