android中的spinner动态加载内容

2024-04-29 20:08

本文主要是介绍android中的spinner动态加载内容,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

android中的spinner动态加载数据:

GroupPurchase.java

package jftt.txlong;import java.util.ArrayList;
import java.util.List;import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;public class GroupPurchase extends Activity {private Spinner changeCity;private Button refresh, pre, next;private TextView leftTime, detail, price, citygp;private ImageView images;private ArrayAdapter<String> adapter;private List<String> allItems;private String[] citys = { "北京市", "上海市", "天津市", "福州市" };@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);initView();allItems = new ArrayList<String>();for (int i = 0; i < citys.length; i++) {allItems.add(citys[i]);}adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, allItems);adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);changeCity.setAdapter(adapter);changeCity.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {citygp.setText(changeCity.getSelectedItem().toString() + "今天的团购");Log.i("info-----------", changeCity.getSelectedItem().toString());}@Overridepublic void onNothingSelected(AdapterView<?> arg0) {}});pre.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Log.i("info-----------", "prefer button has pressed!!!");}});next.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Log.i("info-----------", "next button has pressed!!!");}});}private void initView() {changeCity = (Spinner) findViewById(R.id.changeCity);citygp = (TextView)findViewById(R.id.citygp);refresh = (Button) findViewById(R.id.refresh);pre = (Button) findViewById(R.id.pre);next = (Button) findViewById(R.id.next);leftTime = (TextView) findViewById(R.id.lefttime);detail = (TextView) findViewById(R.id.detail);images = (ImageView) findViewById(R.id.images);price = (TextView) findViewById(R.id.price);}
}

 main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><RelativeLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><Spinner android:id="@+id/changeCity" android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_alignParentLeft="true"/><TextView android:text="郑州今日团购" android:id="@+id/citygp"android:layout_width="wrap_content" android:layout_height="wrap_content"android:layout_toLeftOf="@+id/refresh"/><Button android:text="刷新"android:id="@+id/refresh"android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true"/></RelativeLayout><RelativeLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><TextView android:text="剩余时间:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true"/><TextView android:id="@+id/lefttime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"/><Button android:text="订购" android:id="@+id/order"android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true"/></RelativeLayout><TextView android:id="@+id/detail"android:layout_width="fill_parent"android:layout_height="wrap_content"/><LinearLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><ImageView android:id="@+id/images"android:layout_width="wrap_content"android:layout_height="wrap_content"/><TextView android:id="@+id/price"android:layout_width="wrap_content"android:layout_height="wrap_content"/></LinearLayout><RelativeLayout android:layout_width="fill_parent"android:layout_height="wrap_content"><Button android:id="@+id/pre"android:text="上一个"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"/><Button android:id="@+id/next"android:text="下一个"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"/></RelativeLayout></LinearLayout>
 

这篇关于android中的spinner动态加载内容的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

Android实现在线预览office文档的示例详解

《Android实现在线预览office文档的示例详解》在移动端展示在线Office文档(如Word、Excel、PPT)是一项常见需求,这篇文章为大家重点介绍了两种方案的实现方法,希望对大家有一定的... 目录一、项目概述二、相关技术知识三、实现思路3.1 方案一:WebView + Office Onl

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

Python实现word文档内容智能提取以及合成

《Python实现word文档内容智能提取以及合成》这篇文章主要为大家详细介绍了如何使用Python实现从10个左右的docx文档中抽取内容,再调整语言风格后生成新的文档,感兴趣的小伙伴可以了解一下... 目录核心思路技术路径实现步骤阶段一:准备工作阶段二:内容提取 (python 脚本)阶段三:语言风格调

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字