android——Spinner下拉列表案例详解

代码实现:

下拉列表内容可以在后台获取存放到数组中,可以在前台strings.xml中定义

strings.xml

<?xml version="1.0" encoding="utf-8"?>

SpinnerDemo

Hello world!

选择性别

activity_main.xml

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:id=“@+id/LinearLayout1”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”

tools:context=“ r e l a t i v e P a c k a g e . {relativePackage}. relativePackage.{activityClass}” >

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“性别” />

<Spinner

android:id=“@+id/spinner1”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:prompt=“@string/title”

android:entries=“@array/sex”/>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“课程” />

<Spinner

android:id=“@+id/spinner2”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”/>

<Button

android:id=“@+id/button”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“显示选项” />

MainActivity.java

package com.example.spinnerdemo;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemSelectedListener;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.Spinner;

最后

对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长。而不成体系的学习效果低效漫长且无助。时间久了,付出巨大的时间成本和努力,没有看到应有的效果,会气馁是再正常不过的。

所以学习一定要找到最适合自己的方式,有一个思路方法,不然不止浪费时间,更可能把未来发展都一起耽误了。

如果你是卡在缺少学习资源的瓶颈上,那么刚刚好我能帮到你。

  • 20
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值