Go Android's Custom adapter

Source: Internet
Author: User

The ListView is a very high-utilization view of the actual development, and the general system comes with an adapter that does not meet the needs of the development, which requires the developer to customize the adapter so that the ListView has a good display effect.

There is a demo that implements a mixed list of picture text.

Package Com.example.work;import Java.util.arraylist;import java.util.hashmap;import java.util.list;import android. R.integer;import android.os.bundle;import android.app.activity;import Android.view.menu;import Android.view.View; Import Android.widget.adapterview;import Android.widget.toast;import Android.widget.adapterview.onitemclicklistener;import Android.widget.listview;public class MainActivity extends    Activity {private ListView listview;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        ListView = (ListView) Findviewbyid (R.id.id_list);         This sets three list items, each corresponding to a picture and the corresponding text//picture array int image[] = new int[]{r.drawable.tou1,r.drawable.tou3,r.drawable.he};        Text array String text[] = {"Watch again", "Bucket Landlord", "Love Elimination"};        list

Custom Adapters:

Package Com.example.work;import Java.util.arraylist;import Java.util.hashmap;import java.util.list;import Java.util.map;import Android.content.context;import Android.view.layoutinflater;import Android.view.View;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.imageview;import Android.widget.textview;public class Myadapter extends baseadapter{private context context;//context private int re sourceid;//the layout file of a list item private list

Main activity Layout file:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "      tools:context= ". Mainactivity ">   <listview        android:layout_width=" match_parent "       android:layout_height=" Match_ Parent "       android:id=" @+id/id_list "       ></ListView></LinearLayout>

List item Layout:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "Horizontal" >            <imageview android:layout_width= "50DP"        android:layout_height= "50DP        " Android:id= "@+id/id_image"        />    <textview         android:layout_width= "Match_parent"        android: layout_height= "Wrap_content"        android:id= "@+id/id_textview"        android:gravity= "center_vertical        " Android:textstyle= "Bold|italic"        /></linearlayout>

This article turns from: Android Development _ Talking about ListView (custom adapter)

Go Android's Custom adapter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.