所花时间:3小时
代码量:309
博客篇:1
使用自定义表格查询示例,
总结统计:
package com.example.studyapplication; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.RelativeLayout; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import java.sql.SQLException; public class statsFinal extends AppCompatActivity implements View.OnClickListener { private LinearLayout mainLinerLayout; private RelativeLayout relativeLayout; private Ststats[] s=new Ststats[100]; private Button bt_final; private String[] name={"序号","学号","姓名","班级","发表总次数"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stats_final); for(int i=0;i<100;i++){ s[i]=new Ststats(); } bt_final = findViewById(R.id.bt_final); bt_final.setOnClickListener(this); mainLinerLayout = (LinearLayout) this.findViewById(R.id.MyTable); initData(); } private void initData() { //初始化标题 relativeLayout = (RelativeLayout) LayoutInflater.from(statsFinal.this).inflate(R.layout.table, null); MyTableTextView title = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_1); title.setText(name[0]); title.setTextColor(Color.BLUE); title = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_2); title.setText(name[1]); title.setTextColor(Color.BLUE); title = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_3); title.setText(name[2]); title.setTextColor(Color.BLUE); title = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_4); title.setText(name[3]); title.setTextColor(Color.BLUE); title = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_5); title.setText(name[4]); title.setTextColor(Color.BLUE); mainLinerLayout.addView(relativeLayout); new Thread(new Runnable() { @Override public void run() { Dao d =new Dao(); try { s=d.statsFinal(); } catch (SQLException e) { throw new RuntimeException(e); } } }).start(); //初始化内容 } @Override public void onClick(View v) { int number = 1; int i=0; while (s[i].getId()!=null){ relativeLayout = (RelativeLayout) LayoutInflater.from(statsFinal.this).inflate(R.layout.table, null); MyTableTextView txt = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_1); txt.setText(String.valueOf(number)); txt = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_2); txt.setText(s[i].getId()); txt = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_3); txt.setText(s[i].getName()); txt = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_4); txt.setText(s[i].getUnit()); txt = (MyTableTextView) relativeLayout.findViewById(R.id.list_1_5); txt.setText(s[i].getNum()); mainLinerLayout.addView(relativeLayout); number++; i++; } } }
标签:widget,androidx,private,3.30,import,android,view From: https://www.cnblogs.com/chukjbgg333/p/18106953