Your SlideShare is downloading. ×
List adapter with multiple objects
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

List adapter with multiple objects

527
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
527
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Disclaimer:This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  • 2. LIST ADAPTER WITH MULTIPLE OBJECTS• FREDDY PV email/facebook id : f4freddy@gmail.com
  • 3. What is an adapter in android?• An Adapter object acts as a bridge between an AdapterView and the underlying data for that view.• The Adapter provides access to the data items.• The Adapter is also responsible for making a View for each item in the data set.
  • 4. What is AdapterView Class?• The AdapterView is a child class of ViewGroup> A special kind of container of view objects (list items)• Typically you are going to use subsclasses of AdapterView class instead of using it directly• Example subclasses of AdapterView class> ListView> Spinner> Gallery• An AdapterView access the data through Adapter object Instead of accessing data directly itself
  • 5. ListView• ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view thats placed into the list.
  • 6. First create a class for listactivitypublic class ListMobileActivity extends ListActivity { static final String[] name = new String[] { "freddy", "jaison", "kiran", "syam"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setListAdapter(new ArrayAdapter<String>(this, R.layout.list_mobile, // R.id.label, MOBILE_OS)); setListAdapter(new MobileArrayAdapter(this, name)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { //get selected items String selectedValue = (String) getListAdapter().getItem(position); Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show(); }}
  • 7. Then create a class for the arrayadapterpublic class MobileArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MobileArrayAdapter(Context context, String[] values) { super(context, R.layout.list_name, values); this.context = context; this.values = values; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_name, parent, false); TextView textView = (TextView) rowView.findViewById(R.id.label); ImageView imageView = (ImageView) rowView.findViewById(R.id.logo); textView.setText(values[position]); // Change icon based on name String s = values[position]; System.out.println(s); if (s.equals("freddy")) { imageView.setImageResource(R.drawable.freddy_image); } else if (s.equals("jaison")) { imageView.setImageResource(R.drawable.jaison_image); } else if (s.equals("kiran")) { imageView.setImageResource(R.drawable.kiran_image); } else { imageView.setImageResource(R.drawable.syam_imge); } return rowView; }}
  • 8. Then create an xml file to view this list•• <?xml version="1.0" encoding="utf-8"?>• <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"• android:layout_width="wrap_content"• android:layout_height="wrap_content"• android:padding="5dp" >•• <ImageView• android:id="@+id/logo"• android:layout_width="50px"• android:layout_height="50px"• android:layout_marginLeft="5px"• android:layout_marginRight="20px"• android:layout_marginTop="5px"• android:src="@drawable/windowsmobile_logo" >• </ImageView>•• <TextView• android:id="@+id/label"• android:layout_width="wrap_content"• android:layout_height="wrap_content"• android:text="@+id/label"• android:textSize="30px" >• </TextView>•• </LinearLayout>•
  • 9. • If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance.• www.baabtra.com | www.massbaab.com |ww w.baabte.com
  • 10. THANK YOU