[android] 练习使用ListView(一)
练习使用ListView,BaseAdapter,先展示文字的,再练习图片的
MainActivity.java
package com.android.test; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import 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 extends 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, null);
}
TextView tv_image=(TextView) view.findViewById(R.id.tv_image); tv_image.setText(url);
return view;
} @Override
public int getCount() {
// TODO Auto-generated method stub
return Images.IMAGE_URLS.length;
} @Override
public Object getItem(int position) {
return Images.IMAGE_URLS[position];
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
} }
static class Images{
public final static String[] IMAGE_URLS = new String[]{
"http://img.my.csdn.net/uploads/201508/05/1438760758_3497.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760758_6667.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760757_3588.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760756_3304.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760755_6715.jpeg",
"http://img.my.csdn.net/uploads/201508/05/1438760726_5120.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760726_8364.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760725_4031.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760724_9463.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760724_2371.jpg",
"http://img.my.csdn.net/uploads/201508/05/1438760707_4653.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="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lv_images"></ListView>
</LinearLayout>
image_item.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" > <TextView
android:id="@+id/tv_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> </LinearLayout>
[android] 练习使用ListView(一)的更多相关文章
- Android 中关于ListView分割线的设置
今天发现许多App上的listview的item之间的分割线都只显示了右边一部分,而左边的那一半则没有,第一反应则是给分割线设置一张背景图片就ok了: android:divider="@m ...
- Android—自定义控件实现ListView下拉刷新
这篇博客为大家介绍一个android常见的功能——ListView下拉刷新(参考自他人博客,网址忘记了,阅读他的代码自己理解注释的,希望能帮助到大家): 首先下拉未松手时候手机显示这样的界面: 下面的 ...
- Android开发学习——ListView+BaseAdapter的使用
ListView 就是用来显示一行一行的条目的MVC结构 * M:model模型层,要显示的数据 ----people集合 * V:view视图层,用户看到的界面 ...
- Android 如何在 ListView 中更新 ProgressBar 进度
=======================ListView原理============================== Android 的 ListView 的原理打个简单的比喻就是: 演员演 ...
- [Android Pro] android控件ListView顶部或者底部也显示分割线
reference to : http://blog.csdn.net/lovexieyuan520/article/details/50846569 在默认的Android控件ListView在 ...
- android studio中ListView与SQLite的结合使用
Da.java public class Db extends SQLiteOpenHelper { public Db(Context context) { super(context, " ...
- Android学习笔记——ListView
该工程的功能是实现在一个activity中显示一个列表 以下代码是MainActivity.java中的代码 package com.example.listview; import java.uti ...
- Android课程---关于ListView列表视图的学习
activity_ui3.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns ...
- Android UI组件----ListView列表控件详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- Android 长按Listview显示CheckBox,实现批量删除。
ListView实现的列表,如果是可编辑,可删除的,一般都要提供批量删除功能,否则的话,一项一项的删除体验很不好,也给用户带来了很大的麻烦. 实现效果图 具体实现代码 select.xml 主布局文件 ...
随机推荐
- oracle ocp题库变化,052最新考试题及答案整理-30
30.Which is true when a database instance is shut down? A. Only transactional and normal modes wait ...
- 正则表达式,sed简单用法
一. 正则表达式 1. 常见的正则表达式字符 [] 匹配字符集 grep "bl[lo]g" oldboy.txt 表示字符‘l’或者‘o’都可匹配 * 重复前面字符任意次 g ...
- 区分Web服务器、HTTP服务器、应用程序服务器
在学习前端的过程中.进程听到和看到web服务器.HTTP服务器.应用程序服务器,但一直不知道它们有什么区别,迷惑了好久,今天查看的很多博客,终于算是梳理通了,下面我就来总结一下它们的区别,顺别了解一些 ...
- php 的加法
无意间看到了php中关于加,减,乘,除 的计算方法 这里 http://lxr.php.net/source/xref/PHP-5.6/Zend/zend_operators.h#596 static ...
- CH2401 送礼物(双向dfs)
CH2401 送礼物 描述 作为惩罚,GY被遣送去帮助某神牛给女生送礼物(GY:貌似是个好差事)但是在GY看到礼物之后,他就不这么认为了.某神牛有N个礼物,且异常沉重,但是GY的力气也异常的大(-_- ...
- SQLAlachemy 自动提交配置 SQLALCHEMY_COMMIT_ON_TEARDOWN
挖坑:自动提交省去了每次 commit,添加数据对象后立马取 id 返回None 填坑 :立马要取 id 的地方 commit一下
- CocoaPods的PodSpec.json文件用法
最近有时候用最新的CocoaPod的第三方库,有时候发现CocoaPod.org能搜到那个Podfile,但是每次在终端Pod search xxx,每次都搜不到,原来是本地的Podspec没用更新, ...
- linux开机、重启和用户登陆注销
关机&重启命令 基本介绍: shutdown –h now 立该进行关机 shudown -h 1 "hello, 1 分钟后会关机了" shutdown –r no ...
- Linux 通过程序名获取进程ID并Kill
#!/bin/bash pids=$(ps -ef | grep XXX| awk '{print $2}') for pid in $pids do echo $pid kill -9 $pid d ...
- Jenkins windows部署
1.安装jenkins 进入https://jenkins.io/download/,下载windows安装包,解压后运行jenkins.msi进行安装. 配置jenkins (1)打开http:// ...