+ 1

How to add item from custom adapter?

20th Oct 2017, 10:20 AM
Yudi Zulkarnain
Yudi Zulkarnain - avatar
6 Réponses
+ 1
can I get the codes? thx before
5th Nov 2017, 12:36 AM
Yudi Zulkarnain
Yudi Zulkarnain - avatar
0
do class to your item then do constructor , getter and setter for this item , then do class extends from base adapter , then do array list in this class and make constructor with parameter array list
4th Nov 2017, 3:18 PM
Eslam Mohamed
Eslam Mohamed - avatar
0
ok no problem , wait
5th Nov 2017, 10:10 AM
Eslam Mohamed
Eslam Mohamed - avatar
0
Step1:add new layout cause add in it text and image or any item. Step2:in main layout add listview and give it ID . Step3:add new class to define the variables to connect it with text or …, and make a constructor . Step4:in main activity(Class): make public class and extends from BaseAdapter . Step5: define an object from your class in array list , make a constructor and implement the functions . Step6:define object from layoutinflater and view ; In main activity (class): ListView ls=(ListView)findViewById(R.id.list); ArrayList < Your Class >arrayList=new ArrayList <Your Class>(); arrayList.add(new Your Class ("Eslam","He is A Good Man")); arrayList.add(new Your Class ("Mohamed","He is A Good Man")); arrayList.add(new Your Class ("Yasser","He is A Good Man")); ad arrayabd=new ad(arrayList); ls.setAdapter(arrayabd); In BaseAdapter Class : public class ad extends BaseAdapter{ ArrayList <your Class>arrayList=new ArrayList <Your Class>(); public ad(ArrayList< Your Class > arrayList) { this.arrayList = arrayList; } @Override public int getCount() { return arrayList.size(); } @Override public Object getItem(int position) { return arrayList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater layoutInflater=getLayoutInflater(); View view=layoutInflater.inflate(R.layout.row_item,null); TextView tname=(TextView)view.findViewById(R.id.name); TextView tdesc=(TextView)view.findViewById(R.id.desc); tname.setText(arrayList.get(position).name); tdesc.setText(arrayList.get(position).Desc); return view; } }
5th Nov 2017, 10:51 AM
Eslam Mohamed
Eslam Mohamed - avatar
0
i hope that's help you
5th Nov 2017, 10:51 AM
Eslam Mohamed
Eslam Mohamed - avatar
0
oke, thx so much.. it works
9th Aug 2018, 4:34 AM
Yudi Zulkarnain
Yudi Zulkarnain - avatar