[android] 练习使用ListView(一)

[android] 练习使用ListView(一),第1张

概述练习使用ListView,BaseAdapter,先展示文字的,再练习图片的 MainActivity.java activity_main.xml image_item.xml

练习使用ListVIEw,BaseAdapter,先展示文字的,再练习图片的

MainActivity.java

package com.androID.test;import androID.app.Activity; androID.os.Bundle; androID.vIEw.VIEw; androID.vIEw.VIEwGroup; androID.Widget.BaseAdapter; androID.Widget.listadapter; androID.Widget.ListVIEw; androID.Widget.TextVIEw;public class MainActivity extends Activity {    private ListVIEw lv_images;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        lv_images = (ListVIEw) findVIEwByID(R.ID.lv_images);        listadapter adapter = new ImageAdapter();        lv_images.setAdapter(adapter);    }    /**     * 适配器     * @author taoshihan     *     */    class ImageAdapter  BaseAdapter {        @OverrIDe        public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {            String url=(String) getItem(position);            VIEw vIEw;            if(convertVIEw!=null){                vIEw=convertVIEw;            }else{                vIEw=VIEw.inflate(getApplicationContext(),R.layout.image_item,);            }            TextVIEw tv_image=(TextVIEw) vIEw.findVIEwByID(R.ID.tv_image);                        tv_image.setText(url);            return vIEw;        }        @OverrIDe         getCount() {            // Todo auto-generated method stub             Images.IMAGE_URLS.length;        }        @OverrIDe        public Object getItem( position) {             Images.IMAGE_URLS[position];        }        @OverrIDe        long getItemID( position;        }    }    static class Images{        final static String[] IMAGE_URLS =  String[]{            "http://img.my.csdn.net/uploads/201508/05/1438760758_3497.jpg","http://img.my.csdn.net/uploads/201508/05/1438760758_6667.jpg"        };    }}

activity_main.xml

<?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="wrap_content"    androID:orIEntation="vertical">    ListVIEw         androID:layout_wIDth        androID:layout_height        androID:ID="@+ID/lv_images"></ListVIEw></linearLayout>

image_item.xml

="vertical" >    TextVIEw        androID:ID="@+ID/tv_image"        androID:layout_wIDth="wrap_content"/>>

 

总结

以上是内存溢出为你收集整理的[android] 练习使用ListView(一)全部内容,希望文章能够帮你解决[android] 练习使用ListView(一)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1121186.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存