Android课程---关于下拉列表与状态栏提示的学习

activity_ui7.xml

<?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.test5.UIActivity7"
android:orientation="vertical"> <AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="自动完成的文本编辑框"
android:id="@+id/actv_1"/> <Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sp_1"></Spinner>
<!--Spinner:下拉列表--> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="显示状态栏提示"
android:onClick="notification_OnClick"/> </LinearLayout>

UIActivity7.java

package com.hanqi.test5;

import android.app.Notification;
import android.app.NotificationManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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 UIActivity7 extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui7); AutoCompleteTextView actv_1 = (AutoCompleteTextView)findViewById(R.id.actv_1); //设置自动完成的数据源
String[] strings = {"China","Child","Chile","Chinese","Add","All","Class"}; ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.layout_array,strings); actv_1.setAdapter(arrayAdapter); //下拉列表
Spinner sp_1 = (Spinner)findViewById(R.id.sp_1);
sp_1.setAdapter(arrayAdapter);
sp_1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(UIActivity7.this, "position = " + position, Toast.LENGTH_SHORT).show();
} @Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(UIActivity7.this, "什么也没选", Toast.LENGTH_SHORT).show(); }
}); }
public void notification_OnClick(View v)
{
//获取状态栏消息管理器 产生状态栏提示
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //构造状态栏消息
Notification nt = new Notification.Builder(this)
.setContentTitle("这是一条通知")
.setContentText("这是通知内容:明天要休息了")
.setTicker("显示在状态栏的新通知")
.setSmallIcon(R.drawable.vipflower)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND) .build(); //交给管理器发通知
nm.notify(0,nt); }
}

显示效果如下:

Android课程---关于下拉列表与状态栏提示的学习

Android课程---关于下拉列表与状态栏提示的学习

Android课程---关于下拉列表与状态栏提示的学习

Android课程---关于下拉列表与状态栏提示的学习

上一篇:Resellerclub –Cpanel 主机中如何设置 index 缺省首页


下一篇:cmd运行java程序,无黑框闪烁