android中ProgressBar和ListView
ProgressBar进度条的使用情况:
进度条的.xml声明:如果不声明格式,则默认格式为转圆圈的形式,声明进度条的visibility为不可见。
<ProgressBar
android:id="@+id/firstBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/secondBar"
android:layout_below="@id/firstBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
.java文件控制进度条的代码:
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
firstBar.setMax(200); //设置进度条的最大值
firstBar.setProgress(50); //设置第一进度
firstBar.setSecondaryProgress(60); //设置第二进度
firstBar.setVisibility(View.GONE); //代码设置不可见
ListView的使用说明:
首先为在listviewmain.xml文件中为ListView设置布局方式:
<LinearLayout android:id="@+id/listLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical">
</ListView>
</LinearLayout>
其次需要给ListView中的内容显示格式添加相应的xml文件(user.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/User_name"
android:layout_width="180dp"
android:layout_height="match_parent"
android:singleLine="true"
android:textSize="10pt" />
<TextView
android:id="@+id/User_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="10pt"
android:gravity="right"/>
</LinearLayout>
在.java文件的onCreate方法中通过ArrayList对象给ListView控件添加内容:
setContentView(R.layout.listviewmain);
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map1 = new HashMap<String,String>();
HashMap<String,String> map2 = new HashMap<String,String>();
HashMap<String,String> map3 = new HashMap<String,String>();
map1.put("user_name", "zhangsan");
map1.put("user_ip", "192.168.1.1");
map2.put("user_name", "lisi");
map2.put("user_ip", "192.168.1.12");
map3.put("user_name", "wangwu");
map3.put("user_ip", "192.168.1.18");
list.add(map1);
list.add(map2);
list.add(map3);
SimpleAdapter listAdapter = new SimpleAdapter(this, list, R.layout.user,
new String[]{"user_name","user_ip"}, new int[]{R.id.User_name,R.id.User_id});
setListAdapter(listAdapter);
通过onListItemClick方法监听到底点击了哪个ListView的哪个View:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
//v被点击控件的对象,position被点击控件的位置,id被点击控件的Id
super.onListItemClick(l, v, position, id);
if(id == 0){
//点击了第一行
}
}
android中ProgressBar和ListView的更多相关文章
- Android中动态更新ListView(转)
在使用ListView时,会遇到当ListView列表滑动到最底端时,添加新的列表项的问题,本文通过代码演示如何动态的添加新的列表项到ListView中.实现步骤:调用ListView的setOnSc ...
- android中ScrollView嵌套ListView或GridView显示位置问题
Android中ScrollView中嵌套ListView或GridView时在开始进入界面时总是显示中间位置,开头的位置显示不出来.这种情况下只需要在ScrollView的父控件中添加以下两行代码即 ...
- Android中一个关于ListView的奇怪问题
今天在做项目的时候发现了一个比较奇怪的问题,是关于ListView的,即ListView的android:height属性会影响程序中ListView的getView()方法的调用次数,如果设置Lis ...
- android中的Section ListView
前几天,和ios开发的同事扯淡时发现iphone里有个section listview,分章节的列表.android中的联系人也有这种效果,首字母相同的联系人会被分在一个章节中. 后来搜了一下,and ...
- Android中监听ListView滑动到底部
Android中的应用就是ListView中向下滑动加载更多的功能,不要再onScroll方法中进行判断,那样当滑动到底部的时候,触摸屏幕就会又去加载更多,效果很差,可以自行测试一下: listvie ...
- Android中ProgressBar的使用-通过Handler与Message实现进度条显示
场景 进度条效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为 ...
- Android中取消GridView & ListView默认的点击背景色
方法一: gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); listView.setSelector(new ColorDrawa ...
- Android中GridView、ListView 的 getChildAt() 方法返回null 问题
开发的Android app用到了GridView或者ListView,通常使用getChildAt(int position)方法获取当前点击或者选中的View(即position对应的View). ...
- Android中ProgressBar显示小数的方法
Android原生的ProgressBar的ProgressDialog.STYLE_HORIZONTAL(即水平样式)默认setMax和setProgress只能传int型的参数,而实际项目中我需要 ...
随机推荐
- java反射机制,通过类名获取对象,通过方法名和参数调
import java.lang.reflect.Method; import javax.persistence.Table; /** * 通过注解javax.persistence.Tabl ...
- qt5.5 qtcreator中文乱码
MSVC2010默认保存GBK编码.如果不转换成utf-8编码,对GBK编码的文件,中文可以直接用QStringLiteral()宏,如:QMessageBox msgBox;msgBox.setTe ...
- 关于全排列 next_permutation() 函数的用法
这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...
- 人人都是 DBA(XII)查询信息收集脚本汇编
什么?有个 SQL 执行了 8 秒! 哪里出了问题?臣妾不知道啊,得找 DBA 啊. DBA 人呢?离职了!!擦!!! 程序员在无处寻求帮助时,就得想办法自救,努力让自己变成 "伪 DBA& ...
- 浅谈Excel开发:十一 针对64位Excel的插件的开发和部署
自Office 2010版本开始有了32位和64位之分,对Excel来说,32位的Excel和64位的Excel在性能上的主要区别是64位的Excel能够处理2G及2G以上的大数据集. 随着64位操作 ...
- Express4 启航指南
确实有感而发,Nodejs真的发展太快了,这么说的原因有两点:自己去年冬天买了本<了不起的Node.js>,里面介绍Express的版本还是2.x.x:前些天小伙伴买了本<Node. ...
- 久违的问候-----eclipse中搭建maven项目2016年
好久没有写过博客了,可是一直向别人推荐自己的博客,深感惭愧!今天再次在寒冷之夜继续code,config,write. 接下来,我们就来谈下eclipse中搭建maven web工程的步骤!虽然就是一 ...
- EF连接PostgreSql
1.用nuget安装npgsql和EF 注意,Nuget一定要安装Npgsql的2.2.7版本,更高版本nuget在后面安装EF的时候无法自动解析. install-Package Npgsql -V ...
- maven profile的使用
作为一名程序员,在开发的过程中,经常需要面对不同的运行环境(开发环境.测试环境.生产环境.内网环境.外网环境等等),在不同的环境中,相关的配置一般不一样,比如数据源配置.日志文件配置.以及一些软件运行 ...
- 生成模型(Generative Model)与判别模型(Discriminative Model)
摘要: 1.定义 2.常见算法 3.特性 4.优缺点 内容: 1.定义 1.1 生成模型: 在概率统计理论中, 生成模型是指能够随机生成观测数据的模型,尤其是在给定某些隐含参数的条件下.它给观测值和标 ...