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

相关文章

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

Mybatis嵌套子查询动态SQL编写实践

《Mybatis嵌套子查询动态SQL编写实践》:本文主要介绍Mybatis嵌套子查询动态SQL编写方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、实体类1、主类2、子类二、Mapper三、XML四、详解总结前言MyBATis的xml文件编写动态SQL

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

SpringBoot实现Kafka动态反序列化的完整代码

《SpringBoot实现Kafka动态反序列化的完整代码》在分布式系统中,Kafka作为高吞吐量的消息队列,常常需要处理来自不同主题(Topic)的异构数据,不同的业务场景可能要求对同一消费者组内的... 目录引言一、问题背景1.1 动态反序列化的需求1.2 常见问题二、动态反序列化的核心方案2.1 ht

golang实现动态路由的项目实践

《golang实现动态路由的项目实践》本文主要介绍了golang实现动态路由项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习... 目录一、动态路由1.结构体(数据库的定义)2.预加载preload3.添加关联的方法一、动态路由1