• Android——适配器其他组件(AutoCompleteTextView:自动完成文本编辑框;Spinner:下拉列表)


    activity_activitywenben.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
    
        <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/atv_1"
            android:hint="自动完成文本编辑框"/>
    
        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/sper_1">
        </Spinner>
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="显示状态栏提示"
            android:onClick="notification_onclick"/>
    </LinearLayout>

    java

    package com.example.chenshuai.test321;
    
    import android.app.Notification;
    import android.app.NotificationManager;
    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 Activitywenben extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_activitywenben);
    
            //自动提示文本框
            AutoCompleteTextView autv_1 = (AutoCompleteTextView)findViewById(R.id.atv_1);
    
            //设置数据源
    
            String[] str = {"a","aa","aaa","ab","abc","abcd"};
    
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.listview_layout,str);
    
            autv_1.setAdapter(adapter);
    
            //下拉列表
            Spinner sper_1 = (Spinner)findViewById(R.id.sper_1);
    
            sper_1.setAdapter(adapter);
    
            sper_1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    
                    Toast.makeText(Activitywenben.this, "position" +position, Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> parent) {
    
                    Toast.makeText(Activitywenben.this, "什么也不选", Toast.LENGTH_SHORT).show();
    
                }
            });
        }
    
        public void notification_onclick(View view){
    
            //1.获取状态栏消息管理器
            NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    
            //
            Notification nt = new Notification.Builder(this)
    
                    .setContentTitle("这是一条消息通知")
                    .setContentText("hello world  通知:明天休息")
                    .setTicker("显示在状态栏中的信息")
                    .setSmallIcon(R.drawable.anniu1)
                    .setAutoCancel(true)
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .build();
    
            //交给管理器发出消息
            manager.notify(0,nt);
        }
    }

  • 相关阅读:
    课程的正确步调——Leo鉴书74
    poj(1011)——Sticks(经典的dfs+剪枝)
    怎样去除JSP页面提示:Cannot return from outside a function or method.
    SharePoint 2013 中代码创建列表查阅项字段
    王立平--GUI与GUILayout的差别
    zoj How Many Shortest Path
    QVector的内存分配策略
    java中基于TaskEngine类封装实现定时任务
    超越竞争对手的秘密武器-技术重用
    redis-2.6.16源码分析之pub-sub系统
  • 原文地址:https://www.cnblogs.com/Chenshuai7/p/5365271.html
Copyright © 2020-2023  润新知