-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomListAdapter.java
More file actions
50 lines (38 loc) · 1.61 KB
/
CustomListAdapter.java
File metadata and controls
50 lines (38 loc) · 1.61 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
package com.tobiloba.mydiary;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class CustomListAdapter extends ArrayAdapter {
//to reference the activity
private final Activity context;
//to line up the list topics
private final String[] topicArray;
//to reference the about array
private final String[] aboutArray;
//to reference the chapter
private final String[] chapterArray;
public CustomListAdapter(Activity context, String[] topicArray, String[] aboutArray , String[] chapterArray){
super(context, R.layout.row , topicArray);
this.context = context;
this.topicArray= topicArray;
this.aboutArray=aboutArray;
this.chapterArray=chapterArray;
}
public View getView(int position, View view, ViewGroup parent){
LayoutInflater inflater = context.getLayoutInflater();
@SuppressLint({"InflateParams", "ViewHolder"}) View rowView = inflater.inflate(R.layout.row,null,true);
//this code gets reference to the row.xml file
TextView topic =rowView.findViewById(R.id.Topic);
TextView about = rowView.findViewById(R.id.about);
TextView chapter =rowView.findViewById(R.id.chapter);
//this codes sets the objects to a values from the arrays
topic.setText(topicArray[position]);
about.setText(aboutArray[position]);
chapter.setText(chapterArray[position]);
return rowView;
}
}