Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/PojavLauncher
Path: blob/v3_openjdk/app_pojavlauncher/src/main/java/com/kdt/SimpleArrayAdapter.java
2129 views
1
package com.kdt;
2
3
import android.content.Context;
4
import android.view.LayoutInflater;
5
import android.view.View;
6
import android.view.ViewGroup;
7
import android.widget.ArrayAdapter;
8
import android.widget.BaseAdapter;
9
import android.widget.TextView;
10
11
import androidx.annotation.NonNull;
12
import androidx.annotation.Nullable;
13
14
import java.util.Collections;
15
import java.util.List;
16
17
/**
18
* Basic adapter, expect it uses the what is passed by the code, no the resources
19
* @param <T>
20
*/
21
public class SimpleArrayAdapter<T> extends BaseAdapter {
22
private List<T> mObjects;
23
public SimpleArrayAdapter(List<T> objects) {
24
setObjects(objects);
25
}
26
27
public void setObjects(@Nullable List<T> objects) {
28
if(objects == null){
29
if(mObjects != Collections.emptyList()) {
30
mObjects = Collections.emptyList();
31
notifyDataSetChanged();
32
}
33
} else {
34
if(objects != mObjects){
35
mObjects = objects;
36
notifyDataSetChanged();
37
}
38
}
39
}
40
41
@Override
42
public int getCount() {
43
return mObjects.size();
44
}
45
46
@Override
47
public T getItem(int position) {
48
return mObjects.get(position);
49
}
50
51
@Override
52
public long getItemId(int position) {
53
return position;
54
}
55
56
@NonNull
57
@Override
58
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
59
if(convertView == null){
60
convertView = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
61
}
62
63
TextView v = (TextView) convertView;
64
v.setText(mObjects.get(position).toString());
65
return v;
66
}
67
}
68
69