• 自动文本框,下拉列表,信息提示


    package com.hanqi.zuoye;
    
    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 zidongwenbenActivity extends AppCompatActivity {
        AutoCompleteTextView at;
        Spinner spinner;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_zidongwenben);
            at=(AutoCompleteTextView)findViewById(R.id.at);
            spinner=(Spinner)findViewById(R.id.sp);
            //准备数据源
            String [] strings={"abc","bbc","aaa","ccb","你好","你们","好不的撒","bba","ddd"};
            //准备适配器
            ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this,R.layout.array_liebiao,strings);
            //设置适配器
            at.setAdapter(arrayAdapter);
    
              //下拉列表
            final String []string={"高中","大专","本科","硕士","博士"};
            ArrayAdapter<String> arrayAdapter1=new ArrayAdapter<String>(this,R.layout.array_liebiao,string);
            spinner.setAdapter(arrayAdapter1);
    
            //监听
            spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    Toast.makeText(zidongwenbenActivity.this, "选中的是"+ string[position], Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    Toast.makeText(zidongwenbenActivity.this, "什么也没选", Toast.LENGTH_SHORT).show();
                }
            });
        }
        //发送状态栏消息
        public void bt(View v){
            //1.得到状态栏消息管理器
            NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    
            //准备PendingIntent
            //1)创建Intent
            Intent i=new Intent(this,liebiao2Activity.class);
    
            //2)生成
           PendingIntent pi= PendingIntent.getActivity(this, 0, i, 0);
    
            //2.构建状态栏消息
            Notification nt=new Notification.Builder(this)
                    .setContentTitle("天气预报")
                    .setContentText("晴,气温30度")
                    .setSmallIcon(R.drawable.aa)
                    .setTicker("新的天气预报")
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .setAutoCancel(true)
                    .setContentIntent(pi)
                    .build();
            //3.由管理器发送消息
            nm.notify(0,nt);
    
        }
    }

    java代码

    <?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:orientation="vertical"
        tools:context="com.hanqi.zuoye.zidongwenbenActivity">
    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入"
        android:id="@+id/at"
        android:completionHint="1"
        android:completionThreshold="1"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <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"
            android:layout_weight="1"
            ></Spinner>
    
        </LinearLayout>
        <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:text="发送状态栏消息"
            android:onClick="bt"/>
    </LinearLayout>

    视图文件

  • 相关阅读:
    Aster寻路算法1(转)
    谈谈项目纵向项目验收
    要有兴趣
    用c# 操作 文件的方法
    使用ACT进行测试
    Generated servlet error: keyword cannot be resolved or is not a type
    米尔顿艾瑞克森的催眠引导词
    c# webcliend 来制作 网页搜捕器
    网页木马的解决方案
    用Swing实现数据表格功能
  • 原文地址:https://www.cnblogs.com/storm47/p/5519020.html
Copyright © 2020-2023  润新知