layout文件:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hanqi.testapp2.TestActivity10"
android:orientation="vertical"> <AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入"
android:id="@+id/at_1"
android:completionThreshold="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="学历:"/>
<Spinner
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/sp_1"></Spinner>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发送状态栏消息"
android:onClick="bt_onClick"/>
</LinearLayout>

java类:

 package com.hanqi.testapp2;

 import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Spinner;
import android.widget.Toast; public class TestActivity10 extends AppCompatActivity { AutoCompleteTextView at_1;
Spinner sp_1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
at_1 = (AutoCompleteTextView)findViewById(R.id.at_1);
sp_1 = (Spinner)findViewById(R.id.sp_1);
//准备数据源
String[] strings = {"abc","and","bea","car","AFcgy","ctret","Auyn"};
//准备适配器
ArrayAdapter<String> arrayAdapter= new ArrayAdapter<String>(this,R.layout.arry_adapter,strings);
//给组件设置适配器
at_1.setAdapter(arrayAdapter); //下拉列表
final String[] xl = {"高中","专科","本科","硕士","博士"};
ArrayAdapter<String> sp = new ArrayAdapter<String>(this,R.layout.arry_adapter,xl);
sp_1.setAdapter(sp);
//监听
sp_1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(TestActivity10.this, "选中的项目是 "+xl[position], Toast.LENGTH_SHORT).show();
} @Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(TestActivity10.this, "什么也没选", Toast.LENGTH_SHORT).show();
}
});
}
//发消息
public void bt_onClick(View v)
{
//1.得到状态栏消息管理器
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //准备PendingIntent
//1)创建Intent
Intent intent = new Intent(this,TestActivity1.class);
//2)生成
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
//2.构建状态栏消息
Notification nt = new Notification.Builder(this)
.setContentTitle("天气预报")
.setContentText("明天晴,气温30°")
.setSmallIcon(R.drawable.gmail)
.setTicker("新的天气预报")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(false)
.setContentIntent(pi)
.build();
//3.由管理器发送消息
nm.notify(0,nt);
}
}

效果图为:

点击状态通知栏会跳转到另一个Activity界面

附相关思维导图:

Android——AutoCompleteTextView、Spinner和消息提示的更多相关文章

  1. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  2. android学习笔记21——消息提示Toast

    消息提示可细分为两种:大量消息提示——当程序有大量图片.信息需要展示时,采用对话框消息提示: 小量消息提示——当程序只有少量信息需要呈现给用户时,采用轻量级的对话框——Toast; Toast ==& ...

  3. Android:Toast简单消息提示框

    Toast是简单的消息提示框,一定时间后自动消失,没有焦点. 1.简单文本提示的方法: Toast.makeText(this, "默认的toast", Toast.LENGTH_ ...

  4. AutoCompleteTextView,Spinner,消息提示

    package com.example.wang.testapp2; import android.app.Notification; import android.app.NotificationM ...

  5. 10. Android框架和工具之 AppMsg(消息提示)

    1. AppMsg 优雅的弹出类似Toast的消息提示,支持3种状态Alert(警告),Confirm(确认)以及Info(消息).        2. AppMsg使用: (1)AppMsg下载地址 ...

  6. Android三种消息提示

    Android消息提示有三种方式: 1  使用Toast显示消息提示框 Toast类用于在屏幕中显示一个提示信息框,该消息提示框没有任何控制按钮,并且不会获得焦点,经过一定时间后自动消失.通常用于显示 ...

  7. 【Android代码片段之六】Toast工具类(实现带图片的Toast消息提示)

    转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/6841266  作者:张燕广 实现的Toast工具类ToastUtil封装 ...

  8. android AutoCompleteTextView和Spinner选中项加亮

    package com.example.spinnerexample; import java.util.ArrayList; import java.util.List; import androi ...

  9. Android应用开发学习之Toast消息提示框

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1.  创建一个Toast对象.可 ...

随机推荐

  1. java---数据格式的验证

    package cc.cococ.trade.util; import java.util.regex.Matcher; import java.util.regex.Pattern; public ...

  2. 经典线程同步 互斥量Mutex

    阅读本篇之前推荐阅读以下姊妹篇: <秒杀多线程第四篇一个经典的多线程同步问题> <秒杀多线程第五篇经典线程同步关键段CS> <秒杀多线程第六篇经典线程同步事件Event& ...

  3. 经典线程同步 关键段CS

    上一篇<秒杀多线程第四篇 一个经典的多线程同步问题>提出了一个经典的多线程同步互斥问题,本篇将用关键段CRITICAL_SECTION来尝试解决这个问题. 本文首先介绍下如何使用关键段,然 ...

  4. VMWare Workstation 10.0 Preview CN

    What's New in the VMware Workstation Technology Preview July 2013 The VMware Workstation team is exc ...

  5. Java知识结构思维导图

  6. 码表由来:ascll码-Gbk2312-GBK-Unicode-UTF-8

    码表ascll码-Gbk2312-GBK-Unicode-UTF-8, ascll是基本的标准码表,GB2312是中文码表,GBK是扩展之后的码表,Unicode是国际通用码表,UTF-8是优化后的U ...

  7. Image Generator (Image Builder)

    如果你想要下载一个预编译好的镜像文件,或者想要尝试整个编译过程,一个替代方案是使用镜像生成器(Image Generator)(以前被叫做Image Builder).这是一个预编译好的OpenWrt ...

  8. Spring中@Resource、@controller注解的含义

    @Resource 注解被用来激活一个命名资源(named resource)的依赖注入,在JavaEE应用程序中,该注解被典型地转换为绑定于JNDI context中的一个对象. Spring确实支 ...

  9. linux上安装mysql

    linux下mysql 最新版安装图解教程 1.查看当前安装的linux版本 命令:lsb_release -a 如下图所示 通过上图中的数据可以看出安装的版本为RedHat5.4,所以我们需要下载R ...

  10. 转载:node.js socket.io

    本文转自:http://www.xiaocai.name/post/cf1f9_7b6507  学习node.js socket.io 使用 用node.js(socket.io)实现数据实时推送 在 ...