• 多线程Demo


    1.软件产品说明:

    2.界面代码

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout
     3     xmlns:android="http://schemas.android.com/apk/res/android"
     4     android:layout_width="match_parent"
     5     android:layout_height="match_parent"
     6     android:orientation="vertical"
     7     >
     8 
     9     <TextView
    10         android:layout_width="match_parent"
    11         android:layout_height="wrap_content"
    12         android:gravity="center"
    13         android:text="学生管理系统"
    14         android:textSize="25dp" />
    15 
    16     <EditText
    17         android:id="@+id/et_name"
    18         android:layout_width="match_parent"
    19         android:layout_height="wrap_content"
    20         android:hint="请输入学号" />
    21 
    22     <EditText
    23         android:id="@+id/et_password"
    24         android:layout_width="match_parent"
    25         android:layout_height="wrap_content"
    26         android:hint="请输入密码" />
    27 
    28 
    29     <LinearLayout
    30         android:layout_width="match_parent"
    31         android:layout_height="wrap_content"
    32         android:gravity="center">
    33 
    34 
    35         <Button
    36             android:id="@+id/submit"
    37             android:layout_width="wrap_content"
    38             android:layout_height="wrap_content"
    39             android:text="登录" />
    40 
    41         <Button
    42             android:id="@+id/quit"
    43             android:layout_width="wrap_content"
    44             android:layout_height="wrap_content"
    45             android:text="退出" />
    46 
    47     </LinearLayout>
    48 
    49 
    50 </LinearLayout>
    <?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">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            
            <ImageView
                android:id="@+id/img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@mipmap/ic_launcher" />
    
            <Button
                android:id="@+id/btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="修改头像"
                android:textColor="@android:color/black" />
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="姓名:"
                android:textColor="@android:color/black" />
    
            <EditText
    
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black" />
        </LinearLayout>
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp">
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="性别:"
                android:textColor="@android:color/black" />
    
            <RadioButton
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="男" />
    
            <RadioButton
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text=" 女" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="班级:"
                android:textColor="@android:color/black" />
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black" />
        </LinearLayout>
    
    
    </LinearLayout>

    3.Java代码

    import android.content.DialogInterface;
    import android.content.Intent;
    import android.support.annotation.Nullable;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        private Button submit;
        private Button quit;
    
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.login);
    
            submit = (Button) findViewById(R.id.submit);
            quit = (Button) findViewById(R.id.quit);
            
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(MainActivity.this, ZhuActivity.class);
    
                    startActivity(intent);
    
                }
            });
            quit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setTitle("提示").setMessage("退出吗?").setIcon(R.mipmap.ic_launcher).setPositiveButton("确定",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show();
                                    finish();
    
                                }
                            }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
    
                        }
                    }).show();
                }
            });
    
        }
    
    }
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    /**
     * Created by lenovo on 2017/3/28.
     */
    public class ZhuActivity extends AppCompatActivity {
    
        private ImageView img;
        Handler handler = new Handler() {
            public void handleMessage(android.os.Message msg) {
                img.setImageBitmap((Bitmap) msg.obj);
            }
        };
        private Button btn;
    
        public Bitmap getInternetPicture(String UrlPath) {
            HttpURLConnection httpURLConnection = null;
            Bitmap bm = null;
            try {
                URL url = new URL(UrlPath);
                httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setRequestMethod("GET");
                httpURLConnection.setReadTimeout(5000);
                httpURLConnection.setConnectTimeout(10000);
                int responseCode = httpURLConnection.getResponseCode();
                if (responseCode == 200) {
                    InputStream is = httpURLConnection.getInputStream();
                    bm = BitmapFactory.decodeStream(is);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
            }
            return bm;
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            img = (ImageView) findViewById(R.id.img);
            btn = (Button) findViewById(R.id.btn);
    
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            String URL = "http://img03.store.sogou.com/app/a/10010016/4b28ac2f2356c137fa4f3ff4b2d1c3db";
                            Bitmap bm = getInternetPicture(URL);
                            Message msg = new Message();
                            msg.obj = bm;
                            handler.sendMessage(msg);
                        }
                    }).start();
                }
            });
    
    
        }
    
    
    }

    4.界面截图

  • 相关阅读:
    centos7.6 redis
    centos7.5 rabbitmq3.7.4
    centos7.6 nfs
    nginx跨域
    Linux进阶教程丨第1章:访问命令行
    Representation Learning for Event-based Visuomotor Policies
    Goland 2019下载和安装(带破解补丁和汉化包)
    Adobe XD CC 2020中文破解版(附破解教程)
    SSH 三步解决免密登录
    cygwin命令行安装
  • 原文地址:https://www.cnblogs.com/mlpzxf/p/6637194.html
Copyright © 2020-2023  润新知