自动完成文本输入框提示,下拉列表,发送状态栏消息,消息提醒
activity_zidongwancheng.xml
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?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.example.lenovo.textapp4.ZidongwanchengActivity" 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="280dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="学历:"/> <Spinner android:layout_width="0dp" android:layout_height="wrap_content" android:id="@+id/sp_1" android:layout_weight="1"></Spinner> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="发送状态栏消息" android:onClick="bt_on"/> </LinearLayout>
1-
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com.example.lenovo.textapp4; 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 ZidongwanchengActivity extends AppCompatActivity { AutoCompleteTextView at_1; Spinner sp_1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zidongwancheng); at_1=(AutoCompleteTextView)findViewById(R.id.at_1); sp_1=(Spinner)findViewById(R.id.sp_1); //准备数据源 String[] strings={"abc","and","Aaf","dsf","sdf","gdg"}; //准备适配器 ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.array_adapter,strings); //给组件设置适配器 at_1.setAdapter(arrayAdapter);
2-
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//下拉列表 final String[] xl={"高中","专科","本科","研究生","博士生"}; ArrayAdapter<String>arrayAdapter1=new ArrayAdapter<String>(this,R.layout.array_adapter,xl); sp_1.setAdapter(arrayAdapter1); //监听器 sp_1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(ZidongwanchengActivity.this, "选中的项目是"+xl[position], Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(ZidongwanchengActivity.this, "没选", Toast.LENGTH_SHORT).show(); } }); }
3-
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//发送状态栏消息
public void bt_on(View v)
{
//1-得到状态栏消息管理器
NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//准备一个PendingIntent
//1)创建一个普通的Intent
Intent intent=new Intent(this,Text1Activity.class);
//2)生成PendingIntent
PendingIntent pi=PendingIntent.getActivity(this, 0, intent, 0);
//2-构建状态栏消息
Notification nt=new Notification.Builder(this)
.setContentTitle("天气预报")
.setContentText("明天 晴,气温30°~60°,没风,干燥")
.setSmallIcon(R.drawable.nnn)
.setTicker("新的天气预报")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setContentIntent(pi)
.build();
//3-由管理器发送消息
nm.notify(0,nt);
}