Android Adapters

Android provides several sub classes of Adapter that are useful for retrieving different kinds of data and building views for an Adapter View . The two most common adapters are:

1. Array Adapter

2. Simple Customer Adapter

Array Adapter

ArrayAdapter adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, myStringArray);

  • The arguments for this constructor are:
  • Your app Context
  • The layout that contains a Text View for each string in the array
  • The string array

    ListView listView = (ListView) findViewById(R.id.listview);

    listView.setAdapter(adapter);

    • Then simply call setAdapter()on your ListView:

AdapterView.OnItemClickListener

 

// Create a message handling object as an anonymous class.
private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position, long id) {
        // Do something in response to the click
    }
};

listView.setOnItemClickListener(mMessageClickedHandler);

 

2 Comments

  1. I just want to say I am just beginner to blogs and really savored you’re web-site. Likely I’m want to bookmark your blog post . You actually have good articles. Bless you for revealing your website page.

2 Trackbacks / Pingbacks

  1. Google
  2. Google

Leave a Reply

Your email address will not be published.


*