zoukankan      html  css  js  c++  java
  • 自动文本框,下拉列表,信息提示

    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>

    视图文件

  • 相关阅读:
    light oj 1105 规律
    light oj 1071 dp(吃金币升级版)
    light oj 1084 线性dp
    light oj 1079 01背包
    light oj 1068 数位dp
    light oj 1219 树上贪心
    light oj 1057 状压dp TSP
    light oj 1037 状压dp
    矩阵快速幂3 k*n铺方格
    矩阵快速幂2 3*n铺方格
  • 原文地址:https://www.cnblogs.com/storm47/p/5519020.html
Copyright © 2011-2022 走看看