6.16 2
package com.zhen; import android.content.Intent; import android.util.Log; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import androidx.core.text.HtmlCompat; import com.zhen.net.OkHttpUtils; import com.zhen.pojp.IP; import org.w3c.dom.Text; import java.beans.IndexedPropertyChangeEvent; public class activity_all extends AppCompatActivity { private int id; private TextView textView; private IP ip; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_all); ip=new IP(); ip.setIp(); Intent intent=getIntent(); if (intent != null) { id = intent.getIntExtra("id", -1); // 使用默认值-1,以防数据不存在 if (id != -1) { showData(id); } else { Toast.makeText(this, "id不存在", Toast.LENGTH_SHORT).show(); } } Log.e("id",String.valueOf(id)); initView(); } private void initView() { textView=findViewById(R.id.text); } private void showData(int id) { OkHttpUtils.getInstance().doGet("http://" + ip.getIp() + ":8080/policy/getById?id=" + id, new CallBack() { @Override public void onSuccess(String result) { textView.setText(HtmlCompat.fromHtml(result, HtmlCompat.FROM_HTML_MODE_LEGACY)); } @Override public void onError(Exception e) { } }); } }