2021.2.16

今天把方法整合了一下,之前定义的对象是分开定义的,显示起来不好调用

public class zong extends AppCompatActivity {
    TextView textView;
    double zong;
    List<thing> thingList;
    Button button;
    Intent intent = new Intent();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zong);
        button = findViewById(R.id.button);
        webs web = new webs();
        thing2 thing2 = new thing2();
        Thread mythread = new Thread(thing2);
        mythread.start();
        try {
            mythread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        thingList = thing2.getThingList();
//        thing2 thing2 = new thing2();
        textView = findViewById(R.id.zong);
//        thingList = thing2.getThingList();
        zong=0;
        for (thing thing : thingList){
            zong = zong+Double.parseDouble(thing.getMoney());
            System.out.println(zong);
        }
        String str = String.valueOf(zong);
        textView.setText(str);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.setClass(zong.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
}
原文地址:https://www.cnblogs.com/buxiang-Christina/p/14914374.html