每日总结 4.8

今天进行了蓝桥杯的考试,考完试后进行了androdi的补货功能。代码如下:

package com.example.jjt;

import androidx.appcompat.app.AppCompatActivity;

import android.app.VoiceInteractor;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.CursorTreeAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.w3c.dom.NameList;

public class BhActivity extends AppCompatActivity {
    private Handler handler=new Handler();
    TextView name,num,nums;
    Button bh_bt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bh);
        name=findViewById(R.id.tv_name);
        num=findViewById(R.id.tv_num);
        nums=findViewById(R.id.tv_nums);
        bh_bt=findViewById(R.id.bu_bt);

        xianshi();

        bh_bt.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String num1=num.getText().toString();
                String name1=name.getText().toString();
                bh(name1,num1);
                nums.setText(num1);
            }

        });
    }

    private void xianshi() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String s1=name.getText().toString();
                String ss=Dbhelper.fins(s1);
                String s=Dbhelper.getInfoByName(s1);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        num.setText(s);
                        nums.setText(ss);
                    }
                });
            }
        }).start();
    }

    private void bh(String start,String num) {
        // 必须新开线程才能连接MySQL数据库
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                   // String num= Dbh.find(start);
                    Dbh.up(start,num);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }).start();

    }
}

 

posted @ 2023-04-08 21:12  一个小虎牙  阅读(13)  评论(0编辑  收藏  举报