zoukankan      html  css  js  c++  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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:orientation="vertical"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="helloworld.com.inspur.demo8.MainActivity">
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt1"
            android:text="提交"/>]
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt2"
            android:text="提交"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt3"
            android:text="提交"/>]
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt4"
            android:text="提交"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tv_show"/>
    </LinearLayout>

    逻辑

    package helloworld.com.inspur.demo8;
    
    import android.content.DialogInterface;
    import android.preference.MultiSelectListPreference;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.support.v7.widget.ScrollingTabContainerView;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.jar.Manifest;
    
    public class MainActivity extends AppCompatActivity {
        private Button bt1,bt2,bt3,bt4;
        String info="";
        private TextView tv_show;
        private String[] args={"java","C++","python"};
        private boolean[] isC={false,false,false};
        List<String> list;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            bt1= (Button)findViewById(R.id.bt1);
            bt2=(Button)findViewById(R.id.bt2);
            bt3= (Button)findViewById(R.id.bt3);
            bt4=(Button)findViewById(R.id.bt4);
            tv_show=(TextView)findViewById(R.id.tv_show);
            list=new ArrayList<String>();
            bt1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog dia= new AlertDialog.Builder(MainActivity.this)
                            .setTitle("hahahha")
                            .setIcon(R.mipmap.ic_launcher)
                            .setItems(args, new DialogInterface.OnClickListener() {
    
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    info=args[which];
                                    AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
                                    builder.setPositiveButton("确认", new DialogInterface.OnClickListener(){
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            tv_show.setText(info);
                                        }
                                    });
                                    builder.create().show();
                                }
                            })
                            .create();
                    dia.show();
                }
            });
    
            bt2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog dia= new AlertDialog.Builder(MainActivity.this)
                            .setTitle("复选框")
                            .setIcon(R.mipmap.ic_launcher)
                            .setMultiChoiceItems(args, isC, new DialogInterface.OnMultiChoiceClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                    if(isChecked){
                                        list.add(args[which]);
                                    }
                                    else{
                                        list.remove(args[which]);
                                    }
                                }
                            })
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                   tv_show.setText(list.toString());
    
                                }
                            })
                            .create();
                     dia.show();
    
                }
            });
    
            bt3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageView image = new ImageView(MainActivity.this);
                    image.setImageResource(R.mipmap.ic_launcher);
                    AlertDialog dia= new AlertDialog.Builder(MainActivity.this)
                            .setTitle("image")
                            .setIcon(R.mipmap.ic_launcher)
                            .setView(image)
                            .setPositiveButton("确定",null)
                            .setNegativeButton("取消",null)
                            .create();
                    dia.show();
    
                }
            });
    
            bt4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog dia= new AlertDialog.Builder(MainActivity.this)
                            .setTitle("single")
                            .setIcon(R.mipmap.ic_launcher)
                            .setSingleChoiceItems(args, 0, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    info=args[which];
                                }
                            })
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    tv_show.setText(info);
    
                                }
                            })
                            .create();
                    dia.show();
    
    
    
                }
            });
    
    
        }
    }
  • 相关阅读:
    PHP与CI学习笔记
    The Sum of the k-th Powers(Educational Codeforces Round 7F+拉格朗日插值法)
    Nastya Hasn't Written a Legend(Codeforces Round #546 (Div. 2)E+线段树)
    Please, another Queries on Array?(Codeforces Round #538 (Div. 2)F+线段树+欧拉函数+bitset)
    Gorgeous Sequence(HDU5360+线段树)
    Subsequence(HDU3530+单调队列)
    Qualification Rounds(Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)+状态压缩)
    Xenia and Weights(Codeforces Round #197 (Div. 2)+DP)
    字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛
    线段树优化建边
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9018510.html
Copyright © 2011-2022 走看看