• 自动提示输入框,下拉列表和状态栏消息


    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);
        }
    }
    View Code
    <?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.TestActivity11"
        android:orientation="vertical">
        <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/at_1"
            android:hint="请输入..."
            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>

  • 相关阅读:
    QT 中如何实现一个简单的动画
    qt 中画线时如何设置笔的颜色和填充
    QT自定义窗口
    qt 中创建一个工作线程(例子)
    QT 获取系统时间
    火狐浏览器 system error code 1722 rpc服务器不可用和谷歌浏览器的插件application/x-print-ladop不支持
    ORA-10858:在要求输入数字处找到非数字字符
    eaeyui-combobox实现组合查询(即实现多个值得搜索)
    Mybatis中的模糊查询
    如何设置像我这样的博客的样式。
  • 原文地址:https://www.cnblogs.com/jiang2538406936/p/5515048.html
Copyright © 2020-2023  润新知