![[android] 练习使用ListView(一),第1张 [android] 练习使用ListView(一),第1张](/aiimages/%5Bandroid%5D+%E7%BB%83%E4%B9%A0%E4%BD%BF%E7%94%A8ListView%EF%BC%88%E4%B8%80%EF%BC%89.png)
练习使用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(一)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)