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. [USACO精选] 第一章 数值计算

    好不容易坑来了传说中的USACO精选,近100题我要是能做完就哈哈哈哈了…继今天学并查集连番受挫之后,决定写一写基础题. #0 负二进制 2014-01-10 其实是想到就会做,不想到就不会做的题,数 ...

  2. matlab调用opencv函数的配置

    环境: VS2010 活动解决方案平台x64 WIN 8.1 Opencv 2.4.3 Matlab 2012a 1.  首先保证vs2010能正确调用opencv函数, 2.  Matlab中选择编 ...

  3. Android文件Apk下载变ZIP压缩包

    在azure云存储中 上传apk文件 使用ie下载 变成zip压缩包 解决方法 编辑 blob 属性和元数据 修改 内容类型 为 application/vnd.android.package-arc ...

  4. Apache虚拟主机(三)

    一.启用 httpd-vhosts.conf 在httpd.conf文件中启用 在文件中搜索:Virtual hosts #Virtual hosts虚拟主机 Include conf/extra/h ...

  5. Servlet三种实现方法(四)

    开发Servlet有三种方式:1.实现Servlet接口2.通过继承GenericServlet3.通过继承HttpServlet 一.实现Servlet接口 需求如下:请使用实现 接口的方式,来开发 ...

  6. 国内android帮助文档镜像网站---http://wear.techbrood.com/develop/index.html

    http://wear.techbrood.com/develop/index.html

  7. Linux安装IDA神器

    1.下载windows版的IDA 版本:6.6.141224打包绿色版:http://pan.baidu.com/s/1kTsXZiJ 密码:jj5q 2.复制全部文件到Linux的文件夹中 3.使用 ...

  8. unity3d基础02

    调试: 在MonoDevelop里可以断点调试,注意绑定unity进程 使用Debug.Log()打印信息 创建游戏对象: GameObject test = GameObject.CreatePri ...

  9. Python学习路程day6

    shelve 模块 shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式 import shelve d = shelve.open ...

  10. 2016- 1- 16 NSThread 的学习

    一:NSThread的概念: 二:NSThread的使用: 1.创建一个Thread 1.1第一种方法: - (void)test1{ NSString *str = @"zhengli&q ...