forked from hussien89aa/AndroidTutorialForBeginners
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListViewAdapter.java
More file actions
Latest commit
81 lines (60 loc) · 2.01 KB
/
Copy pathListViewAdapter.java
File metadata and controls
81 lines (60 loc) · 2.01 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
72
73
74
75
76
77
78
/*
Adapter snaped code for Android apps that have
user id, job title and job description
*/
// adapter class
publicclassAdapterItems
{
publicintID;
publicStringJobTitle;
publicStringDescription;
//for news details
AdapterItems( intID, StringJobTitle,StringDescription)
{
this. ID=ID;
this. JobTitle=JobTitle;
this. Description=Description;
}
}
//display news list
privateclassMyCustomAdapterextendsBaseAdapter {
publicArrayList<AdapterItems> listnewsDataAdpater ;
publicMyCustomAdapter(ArrayList<AdapterItems> listnewsDataAdpater) {
this.listnewsDataAdpater=listnewsDataAdpater;
}
@Override
publicintgetCount() {
returnlistnewsDataAdpater.size();
}
@Override
publicStringgetItem(intposition) {
returnnull;
}
@Override
publiclonggetItemId(intposition) {
returnposition;
}
@Override
publicViewgetView(intposition, ViewconvertView, ViewGroupparent)
{
LayoutInflatermInflater = getLayoutInflater();
ViewmyView = mInflater.inflate(R.layout.layout_ticket, null);
finalAdapterItemss = listnewsDataAdpater.get(position);
TextViewtxtJobTitle=( TextView)myView.findViewById(R.id.txtJobTitle);
txtJobTitle.setText(s.JobTitle);
returnmyView;
}
}
//adapter class
ArrayList<AdapterItems> listnewsData = newArrayList<AdapterItems>();
MyCustomAdaptermyadapter;
//add data and view it
listnewsData.add(newAdapterItems(1,"developer"," develop apps"));
myadapter=newMyCustomAdapter(listnewsData);
ListViewlsNews=(ListView)findViewById(R.id.LVNews);
lsNews.setAdapter(myadapter);//intisal with data
//update data in listview
listnewsData.add(newAdapterItems(2,"tester"," test apps"));
myadapter.notifyDataSetChanged();
//update
//set on clicklinisner