Progressbar的使用以及ListView的使用

2024-06-20 18:38
文章标签 使用 listview progressbar

本文主要是介绍Progressbar的使用以及ListView的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

<?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:orientation="vertical" >
    <ProgressBar 
        android:id="@+id/progressOne"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
        android:visibility="gone"
        />
    
    <ProgressBar 
        android:id="@+id/progressTwo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyle"
        android:visibility="gone"
        />
    
    <Button 
         android:id="@+id/buttonprogress"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="@string/login"
        />

</LinearLayout>


package com.example.helloworld;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;


public class ProgreeeBarTest extends Activity {


private ProgressBar first;
private ProgressBar second;
private Button button;
private int i=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myprogressbar);

//获取对象 
first=(ProgressBar)findViewById(R.id.progressOne);
second=(ProgressBar)findViewById(R.id.progressTwo);
   button=(Button)findViewById(R.id.buttonprogress);
   
   button.setOnClickListener(new ButtonOnClickListener() );


}

class ButtonOnClickListener implements OnClickListener{


@Override
public void onClick(View view) {
if(i==0){
//第一次单机按钮 ,进度条会显示
first.setVisibility(View.VISIBLE);
second.setVisibility(View.VISIBLE);
}else if(i<first.getMax()){
//显示进度条的进度
first.setProgress(i);
first.setSecondaryProgress(i+10);
}else{
//如果读取完毕,进度条消失
first.setVisibility(View.GONE);
second.setVisibility(View.GONE);
}
i=i+10;
}

}
}



ListView的使用

<?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:orientation="vertical" >
    
    <LinearLayout 
        android:id="@+id/listLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >


        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:drawSelectorOnTop="false"
            android:scrollbars="vertical"
            >
        </ListView>
            
    </LinearLayout>


</LinearLayout>


user.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="match_parent"
    android:orientation="vertical" >
    
    <LinearLayout 
        android:id="@+id/listLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >


        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:drawSelectorOnTop="false"
            android:scrollbars="vertical"
            >
        </ListView>
            
    </LinearLayout>


</LinearLayout>


package com.example.helloworld;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SimpleAdapter;


public class ListView extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylistview);

List<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.3");
map2.put("user_name", "lisi");
map2.put("user_ip", "192.168.1.4");
map3.put("user_name", "wangwu");
map3.put("user_ip", "192.168.1.5");

SimpleAdapter adapter=new SimpleAdapter(this, list, R.layout.user, new String[]{"user_name","user_ip"}, new int[]{R.id.user_name,R.id.user_ip});
setListAdapter(adapter);
}

@Override
protected void onListItemClick(android.widget.ListView l, View v,
int position, long id) {
System.out.println(position+"   "+id);
//id 就是第几个
super.onListItemClick(l, v, position, id);
}

}


这篇关于Progressbar的使用以及ListView的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1078937

相关文章

使用Dify访问mysql数据库详细代码示例

《使用Dify访问mysql数据库详细代码示例》:本文主要介绍使用Dify访问mysql数据库的相关资料,并详细讲解了如何在本地搭建数据库访问服务,使用ngrok暴露到公网,并创建知识库、数据库访... 1、在本地搭建数据库访问的服务,并使用ngrok暴露到公网。#sql_tools.pyfrom

使用mvn deploy命令上传jar包的实现

《使用mvndeploy命令上传jar包的实现》本文介绍了使用mvndeploy:deploy-file命令将本地仓库中的JAR包重新发布到Maven私服,文中通过示例代码介绍的非常详细,对大家的学... 目录一、背景二、环境三、配置nexus上传账号四、执行deploy命令上传包1. 首先需要把本地仓中要

Spring Cloud之注册中心Nacos的使用详解

《SpringCloud之注册中心Nacos的使用详解》本文介绍SpringCloudAlibaba中的Nacos组件,对比了Nacos与Eureka的区别,展示了如何在项目中引入SpringClo... 目录Naacos服务注册/服务发现引⼊Spring Cloud Alibaba依赖引入Naco编程s依

Java springBoot初步使用websocket的代码示例

《JavaspringBoot初步使用websocket的代码示例》:本文主要介绍JavaspringBoot初步使用websocket的相关资料,WebSocket是一种实现实时双向通信的协... 目录一、什么是websocket二、依赖坐标地址1.springBoot父级依赖2.springBoot依赖

Java使用Mail构建邮件功能的完整指南

《Java使用Mail构建邮件功能的完整指南》JavaMailAPI是一个功能强大的工具,它可以帮助开发者轻松实现邮件的发送与接收功能,本文将介绍如何使用JavaMail发送和接收邮件,希望对大家有所... 目录1、简述2、主要特点3、发送样例3.1 发送纯文本邮件3.2 发送 html 邮件3.3 发送带

使用DeepSeek搭建个人知识库(在笔记本电脑上)

《使用DeepSeek搭建个人知识库(在笔记本电脑上)》本文介绍了如何在笔记本电脑上使用DeepSeek和开源工具搭建个人知识库,通过安装DeepSeek和RAGFlow,并使用CherryStudi... 目录部署环境软件清单安装DeepSeek安装Cherry Studio安装RAGFlow设置知识库总

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

Spring-AOP-ProceedingJoinPoint的使用详解

《Spring-AOP-ProceedingJoinPoint的使用详解》:本文主要介绍Spring-AOP-ProceedingJoinPoint的使用方式,具有很好的参考价值,希望对大家有所帮... 目录ProceedingJoinPoijsnt简介获取环绕通知方法的相关信息1.proceed()2.g

Maven pom.xml文件中build,plugin标签的使用小结

《Mavenpom.xml文件中build,plugin标签的使用小结》本文主要介绍了Mavenpom.xml文件中build,plugin标签的使用小结,文中通过示例代码介绍的非常详细,对大家的学... 目录<build> 标签Plugins插件<build> 标签<build> 标签是 pom.XML

JAVA虚拟机中 -D, -X, -XX ,-server参数使用

《JAVA虚拟机中-D,-X,-XX,-server参数使用》本文主要介绍了JAVA虚拟机中-D,-X,-XX,-server参数使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有... 目录一、-D参数二、-X参数三、-XX参数总结:在Java开发过程中,对Java虚拟机(JVM)的启动参数进