This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSearchResultAdapter.java
More file actions
69 lines (56 loc) · 2.12 KB
/
SearchResultAdapter.java
File metadata and controls
69 lines (56 loc) · 2.12 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
package com.uwflow.flow_android.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.uwflow.flow_android.R;
import com.uwflow.flow_android.db_object.Course;
import java.util.List;
/**
* Created by jasperfung on 3/4/14.
*/
public class SearchResultAdapter extends BaseAdapter {
private List<Course> mResults;
private Context mContext;
public SearchResultAdapter(List<Course> results, Context context) {
mResults = results;
mContext = context;
}
public int getCount() {
return mResults.size();
}
public Object getItem(int arg0) {
return mResults.get(arg0);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// verify that convertView is not null
if (convertView == null) {
// inflate a new view
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.search_row_item, parent, false);
}
// Fill view with appropriate data
TextView first, second, third, fourth;
first = (TextView) convertView.findViewById(R.id.course_code);
second = (TextView) convertView.findViewById(R.id.course_name);
third = (TextView) convertView.findViewById(R.id.rating);
fourth = (TextView) convertView.findViewById(R.id.rating_count);
final Course course = mResults.get(position);
first.setText(course.getCode());
second.setText(course.getName());
Double rating = course.getOverall().getRating();
if (rating == null) {
third.setText("---");
} else {
third.setText(String.format("%d%%", (int)(rating * 100)));
}
fourth.setText(String.format("%d ratings", (int)(course.getOverall().getCount())));
return convertView;
}
}