10天冲刺第五天
今天做了什么:
咨询师状态界面:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".consulantActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/img_person" android:layout_width="200dp" android:layout_height="200dp" android:scaleType="centerCrop"/> <LinearLayout android:layout_width="match_parent" android:layout_height="200dp" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:orientation="horizontal"> <TextView android:id="@+id/tv_name" android:layout_width="140dp" android:layout_height="match_parent" android:textSize="20dp"/> <TextView android:id="@+id/tv_money" android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="20dp"/> </LinearLayout> <TextView android:id="@+id/tv_intro" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> </LinearLayout> <LinearLayout android:id="@+id/myLinear" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </LinearLayout>
代码:
package com.example.psychological; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.LayoutInflaterCompat; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.example.psychological.javaClass.Consultant; import com.example.psychological.javaClass.Dao; import java.io.IOException; import java.io.InputStream; import java.sql.SQLException; import okhttp3.Call; import okhttp3.Callback; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class consulantActivity extends AppCompatActivity implements View.OnClickListener { private static final String NET="192.168.129.224"; private LinearLayout myLinear; private LinearLayout linearLayout; private ImageView img_person; private String name; private String money; private String intro; private TextView tv_name; private TextView tv_money; private TextView tv_intro; private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what){ case 0: Bitmap bitmap = (Bitmap)msg.obj; img_person.setImageBitmap(bitmap);//将图片的流转换成图片 break; case 1: n = (int)msg.obj; if(n==0){ Button bt = linearLayout.findViewById(R.id.my_bt); bt.setOnClickListener(consulantActivity.this); myLinear.addView(linearLayout); } else if(n==2) { OkHttpClient okHttpClient = new OkHttpClient(); SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); String id = sharedPreferences.getString("id",""); Request request = new Request.Builder() .url("http://"+NET+":8080/apply/download") .addHeader("id",id) .build(); okHttpClient.newCall(request).enqueue(new okhttp3.Callback() { public void onFailure(Call call, IOException e) { } public void onResponse(Call call, Response response) throws IOException { InputStream inputStream = response.body().byteStream();//得到图片的流 Bitmap bitmap = BitmapFactory.decodeStream(inputStream); Message msg = new Message(); msg.obj = bitmap; msg.what = 0; handler.sendMessage(msg); } }); getMess(); Button bt = new Button(consulantActivity.this); bt.setText("修改信息"); bt.setId(R.id.bt1); bt.setOnClickListener(consulantActivity.this); myLinear.addView(bt); } else { TextView tv=new TextView(consulantActivity.this); tv.setText("正在审批中"); tv.setGravity(Gravity.CENTER); tv.setTextSize(20); myLinear.addView(tv); } break; case 3: Consultant c = (Consultant) msg.obj; tv_name.setText(c.getName()); tv_money.setText("¥"+c.getMoney()); tv_intro.setText(c.getIntroduction()); break; } } }; private int n; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_consulant); getSupportActionBar().hide(); img_person = findViewById(R.id.img_person); tv_name = findViewById(R.id.tv_name); tv_money = findViewById(R.id.tv_money); tv_intro = findViewById(R.id.tv_intro); myLinear = (LinearLayout) this.findViewById(R.id.myLinear); linearLayout = (LinearLayout) LayoutInflater.from(consulantActivity.this).inflate(R.layout.button,null); initData(); } @Override public void onClick(View v) { if(v.getId()==R.id.my_bt) { startActivity(new Intent(consulantActivity.this,applyActivity.class)); } else { startActivity(new Intent(consulantActivity.this, updateConActivity.class)); } } public void initData() { new Thread(new Runnable() { @Override public void run() { SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); String id = sharedPreferences.getString("id",""); Dao d =new Dao(); int i=0; try { i = d.haveCon(id); } catch (SQLException e) { throw new RuntimeException(e); } Message message = new Message(); message.what=1; message.obj=i; handler.sendMessage(message); } }).start(); } public void getMess() { new Thread(new Runnable() { @Override public void run() { SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); String id = sharedPreferences.getString("id",""); Dao d = new Dao(); Consultant c =new Consultant(); try { c=d.checkConsultant(id); } catch (SQLException e) { throw new RuntimeException(e); } Message msg = new Message(); msg.what=3; msg.obj=c; handler.sendMessage(msg); } }).start(); }
根据审批状态显示对应界面,如果通过可以修改数据
明天做什么:
咨询师预约界面
今天遇到问题:照片上传