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如何通过http动态操作xxl-job任务

《springboot如何通过http动态操作xxl-job任务》:本文主要介绍springboot如何通过http动态操作xxl-job任务的问题,具有很好的参考价值,希望对大家有所帮助,如有错... 目录springboot通过http动态操作xxl-job任务一、maven依赖二、配置文件三、xxl-

Spring如何使用注解@DependsOn控制Bean加载顺序

《Spring如何使用注解@DependsOn控制Bean加载顺序》:本文主要介绍Spring如何使用注解@DependsOn控制Bean加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录1.javascript 前言2. 代码实现总结1. 前言默认情况下,Spring加载Bean的顺

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局

Android ViewBinding使用流程

《AndroidViewBinding使用流程》AndroidViewBinding是Jetpack组件,替代findViewById,提供类型安全、空安全和编译时检查,代码简洁且性能优化,相比Da... 目录一、核心概念二、ViewBinding优点三、使用流程1. 启用 ViewBinding (模块级

Java实现删除文件中的指定内容

《Java实现删除文件中的指定内容》在日常开发中,经常需要对文本文件进行批量处理,其中,删除文件中指定内容是最常见的需求之一,下面我们就来看看如何使用java实现删除文件中的指定内容吧... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细介绍3.1 Ja

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos

Java调用C#动态库的三种方法详解

《Java调用C#动态库的三种方法详解》在这个多语言编程的时代,Java和C#就像两位才华横溢的舞者,各自在不同的舞台上展现着独特的魅力,然而,当它们携手合作时,又会碰撞出怎样绚丽的火花呢?今天,我们... 目录方法1:C++/CLI搭建桥梁——Java ↔ C# 的“翻译官”步骤1:创建C#类库(.NET

Python实现自动化Word文档样式复制与内容生成

《Python实现自动化Word文档样式复制与内容生成》在办公自动化领域,高效处理Word文档的样式和内容复制是一个常见需求,本文将展示如何利用Python的python-docx库实现... 目录一、为什么需要自动化 Word 文档处理二、核心功能实现:样式与表格的深度复制1. 表格复制(含样式与内容)2

MyBatis编写嵌套子查询的动态SQL实践详解

《MyBatis编写嵌套子查询的动态SQL实践详解》在Java生态中,MyBatis作为一款优秀的ORM框架,广泛应用于数据库操作,本文将深入探讨如何在MyBatis中编写嵌套子查询的动态SQL,并结... 目录一、Myhttp://www.chinasem.cnBATis动态SQL的核心优势1. 灵活性与可

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio