forked from hussien89aa/AndroidTutorialForBeginners
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ListViewAdapter.java
81 lines (60 loc) · 2.01 KB
/
ListViewAdapter.java
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
76
77
78
/*
Adapter snaped code for Android apps that have
user id, job title and job description
*/
// adapter class
public class AdapterItems
{
public int ID;
public String JobTitle;
public String Description;
//for news details
AdapterItems( int ID, String JobTitle,String Description)
{
this. ID=ID;
this. JobTitle=JobTitle;
this. Description=Description;
}
}
//display news list
private class MyCustomAdapter extends BaseAdapter {
public ArrayList<AdapterItems> listnewsDataAdpater ;
public MyCustomAdapter(ArrayList<AdapterItems> listnewsDataAdpater) {
this.listnewsDataAdpater=listnewsDataAdpater;
}
@Override
public int getCount() {
return listnewsDataAdpater.size();
}
@Override
public String getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater mInflater = getLayoutInflater();
View myView = mInflater.inflate(R.layout.layout_ticket, null);
final AdapterItems s = listnewsDataAdpater.get(position);
TextView txtJobTitle=( TextView)myView.findViewById(R.id.txtJobTitle);
txtJobTitle.setText(s.JobTitle);
return myView;
}
}
//adapter class
ArrayList<AdapterItems> listnewsData = new ArrayList<AdapterItems>();
MyCustomAdapter myadapter;
//add data and view it
listnewsData.add(new AdapterItems(1,"developer"," develop apps"));
myadapter=new MyCustomAdapter(listnewsData);
ListView lsNews=(ListView)findViewById(R.id.LVNews);
lsNews.setAdapter(myadapter);//intisal with data
//update data in listview
listnewsData.add(new AdapterItems(2,"tester"," test apps"));
myadapter.notifyDataSetChanged();
//update
//set on clicklinisner