package com.hanqi.testapp2;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
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 TestActivity11 extends AppCompatActivity {
AutoCompleteTextView at_1;
Spinner sp_1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test11);
at_1=(AutoCompleteTextView)findViewById(R.id.at_1);
//准备数据源
String[] strings={"abc","and","ano","aaaa","aout","app"};
//准备适配器
ArrayAdapter<String> aa=new ArrayAdapter<String>(this,R.layout.array_adapter,strings);
//给组件设置适配器
at_1.setAdapter(aa);
sp_1=(Spinner)findViewById(R.id.sp_1);
//下拉列表
final String[] xl={"高中","专科","本科","硕士","博士"};
ArrayAdapter<String> sp=new ArrayAdapter<String>(this,R.layout.array_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(TestActivity11.this, "选中的项目是"+xl[position], Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(TestActivity11.this, "什么也没选", Toast.LENGTH_SHORT).show();
}
});
}
//发消息
public void bt_OnClick(View v)
{
//1.得到状态栏消息管理器
NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//准备PendingIntet
//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.tianqi)
.setTicker("新的天气预报")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)//是否点击跳转后自动消失
.setContentIntent(pi)
.build();
//3.由管理器发送消息
nm.notify(0,nt);
}
}