private ListView listViewParticulars;
private ListView listView;
private ImageButton button;
private List<Particular> particulars;
private ParticularsAdapter particularsAdapter;
private List<Data> dataList;
private DataAdapter dataAdapter;
private int m = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carnumber);
listView = findViewById(R.id.listView_data);
listViewParticulars = findViewById(R.id.listView_par);
button = findViewById(R.id.image_button);
particulars = new ArrayList<>();
particularsAdapter = new ParticularsAdapter(this,R.layout.list2_layout,particulars);
listViewParticulars.setAdapter(particularsAdapter);
dataList = new ArrayList<>();
dataAdapter = new DataAdapter(this,R.layout.list1_layout,dataList,particulars,particularsAdapter);
listView.setAdapter(dataAdapter);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dataList.add(new Data("辽"+m,2,2,1000.0));
particulars.add(new Particular(new Date(),false,"光明","不按规则行驶","2分","1000","辽"+m));
particulars.add(new Particular(new Date(),false,"光明","不按规则行驶","2分","1000","辽"+m));
m++;
runOnUiThread(new Runnable() {
@Override
public void run() {
dataAdapter.notifyDataSetChanged();
particularsAdapter.notifyDataSetChanged();
}
});
}
});
listViewParticulars.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent=new Intent(Carnumber.this, Main12Activity.class);
startActivity(intent);
}
});
}
public class DataAdapter extends ArrayAdapter<Data> {
private int resource;
private List<Data> dataList;
private List<Particular> particulars;
private ParticularsAdapter particularsAdapter;
public DataAdapter(Context context, int resource,List<Data> objects,List<Particular> particulars,ParticularsAdapter particularsAdapter) {
super(context, resource, objects);
this.resource = resource;
this.dataList = objects;
this.particulars = particulars;
this.particularsAdapter = particularsAdapter;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView==null){
convertView = LayoutInflater.from(getContext()).inflate(resource,parent,false);//加载子布局
};
final Data data = getItem(position);
TextView textViewCarNumber = convertView.findViewById(R.id.car_number_nur);
TextView textViewTime = convertView.findViewById(R.id.time);
TextView textViewGrade = convertView.findViewById(R.id.grade);
TextView textViewMoney = convertView.findViewById(R.id.money);
textViewCarNumber.setText(data.getCarNumber());
textViewTime.setText("未处理违章 "+data.getTime()+"次");
textViewGrade.setText("扣"+data.getGrade()+"分");
textViewMoney.setText("罚款"+data.getMoney()+"元");
ImageButton button = convertView.findViewById(R.id.button_minus);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Particular> particularList = new ArrayList<>();
for (int i = 0; i < particulars.size(); i++) {
if (!particulars.get(i).getCarNumber().equals(data.getCarNumber())){
particularList.add(particulars.get(i));
}
}
particulars.clear();
particulars.addAll(particularList);
dataList.remove(data);
particularsAdapter.notifyDataSetChanged();
notifyDataSetChanged();
}
});
return convertView;
}
}
ublic class ParticularsAdapter extends ArrayAdapter<Particular> {
private int resource;
public ParticularsAdapter(Context context, int resource,List<Particular> objects) {
super(context, resource, objects);
this.resource = resource;
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public View getView(int position,View convertView,ViewGroup parent) {
if (convertView==null){
convertView = LayoutInflater.from(getContext()).inflate(resource,parent,false);//加载子布局
}
Particular particular = getItem(position);
TextView textViewData = convertView.findViewById(R.id.date);
TextView textViewYOrN = convertView.findViewById(R.id.yOrN);
TextView textViewWay = convertView.findViewById(R.id.way);
TextView textViewDetails = convertView.findViewById(R.id.details);
TextView textViewGrade = convertView.findViewById(R.id.grade);
TextView textViewMoney = convertView.findViewById(R.id.money);
textViewData.setText(new SimpleDateFormat("yyyy-MM-dd\tHH:mm:ss").format(particular.getData()));
textViewYOrN.setText(particular.getyOrN()==true?"已处理":"未处理");
textViewWay.setText(particular.getWay());
textViewDetails.setText(particular.getDetails());
textViewGrade.setText(particular.getGrade());
textViewMoney.setText(particular.getMoney());
return convertView;
}
}
ublic class Data {
private String carNumber;//车牌
private Integer time;//次数
private Integer grade;//分数
private Double money;//钱
public Data() {
}
public Data(String carNumber, Integer time, Integer grade, Double money) {
this.carNumber = carNumber;
this.time = time;
this.grade = grade;
this.money = money;
}
public String getCarNumber() {
return carNumber;
}
public void setCarNumber(String carNumber) {
this.carNumber = carNumber;
}
public Integer getTime() {
return time;
}
public void setTime(Integer time) {
this.time = time;
}
public Integer getGrade() {
return grade;
}
public void setGrade(Integer grade) {
this.grade = grade;
}
public Double getMoney() {
return money;
}
public void setMoney(Double money) {
this.money = money;
}
}
public class Particular {
private Date data;//时间
private Boolean yOrN;//是否
private String way;//路
private String details;//详情
private String grade;//分
private String money;//钱
private String carNumber;//车牌
public Particular() {
}
public Particular(Date data, Boolean yOrN, String way, String details, String grade, String money, String carNumber) {
this.data = data;
this.yOrN = yOrN;
this.way = way;
this.details = details;
this.grade = grade;
this.money = money;
this.carNumber = carNumber;
}
public String getCarNumber() {
return carNumber;
}
public void setCarNumber(String carNumber) {
this.carNumber = carNumber;
}
public Date getData() {
return data;
}
public void setData(Date data) {
this.data = data;
}
public Boolean getyOrN() {
return yOrN;
}
public void setyOrN(Boolean yOrN) {
this.yOrN = yOrN;
}
public String getWay() {
return way;
}
public void setWay(String way) {
this.way = way;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getMoney() {
return money;
}
public void setMoney(String money) {
this.money = money;
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:background="#58cfcfcf">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="日期"
android:textSize="25sp"
android:id="@+id/date"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="30dp" />
<TextView
android:text="否"
android:textSize="25sp"
android:id="@+id/yOrN"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/way"
android:text="路"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="asdasdadandaskdnaklsanfsakfnaskfas"
android:textSize="25sp"
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/grade"
android:text="扣 2 分"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"/>
<TextView
android:id="@+id/money"
android:text="罚款 250 元"
android:textSize="25sp"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:background="#58cfcfcf">
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_toStartOf="@+id/button_minus"
android:layout_toLeftOf="@+id/button_minus"
android:background="#586c6c6c"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/car_number_nur"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:text="鲁A1003"
android:textSize="30sp" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:text="未处理违章 1 次"
android:textSize="25sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/grade"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="扣 2 分"
android:textSize="25sp" />
<TextView
android:id="@+id/money"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="罚款 250 元"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/button_minus"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="70dp"
android:background="@drawable/sub" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:background="#58cfcfcf">
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_toStartOf="@+id/button_minus"
android:layout_toLeftOf="@+id/button_minus"
android:background="#586c6c6c"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/car_number_nur"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:text="鲁A1003"
android:textSize="30sp" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center"
android:text="未处理违章 1 次"
android:textSize="25sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/grade"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="扣 2 分"
android:textSize="25sp" />
<TextView
android:id="@+id/money"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="罚款 250 元"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/button_minus"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="70dp"
android:background="@drawable/sub" />
</RelativeLayout>
网友评论