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>

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)studio Error: Please sele
  2. Android(安卓)Framework 之HelloWorld(二)
  3. 使用宝塔面板上线项目
  4. 抖音seo源码,抖音seo优化系统源码技术搭建
  5. 新手使用APICloud可视化开发搭建商城主页
  6. 使用APICloud实现文档下载和预览功能
  7. 如何用ps绘制插画肌理?ps肌理插画教程
  8. 本地可视化工具连接阿里云centOS服务器的
  9. VSCode实用插件
  10. 人物的脸怎么画?漫画脸部绘画教程!