package com.example.skbartect; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class Activity2 extends AppCompatActivity { //private只能在本类使用,跳不出去 private ListView LV; private List<String> Intlist; private ArrayAdapter<String> adpt; private Intent IT1;//save private int PC1;//progress1 private String[] array; private int num=3;//迭代计数 private Button BT2; private Intent Intent;//跳转回A页面 private Button BT4; //pubilc在其他类也可以调用 /* IT1=getIntent(); if (IT1!=null){ PC1=IT1.getIntExtra("progress1",0); } array=new int[7]; for (int i=0;i<=7;i++){ array[i]=0; } LV = findViewById(R.id.lv1); list = new ArrayList<>(); for (int i = 0; i < 8; i++) { int a=array[i]; list.add(String.valueOf(a)); } adpt = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list); LV.setAdapter(adpt); */ @Override protected void onCreate(Bundle savedInstanceState) {//页面2用大R,页面1用小r String[] array; array=new String[30];//存数据 int num;//迭代(要两边跳转后还能保持不刷新,就要用到java的点引用 MainActivity main = new MainActivity(); //main.user(100);// Intlist=new ArrayList<>(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_2); BT2 = findViewById(R.id.bt2); LV = findViewById(R.id.lv1); SharedPreferences Record_Two=getSharedPreferences("NUM",MODE_PRIVATE); int NUM=Record_Two.getInt("num",0);//获取按的次数 for (int i=1;i<NUM;i++) { SharedPreferences Record = getSharedPreferences("pgrone" + i, MODE_PRIVATE); int PGROME = Record.getInt("c_one" + i, 0);//获取progress //不要用for循环,试一下就按照原有的数据代入 //for (int i=0;i<NUM;i++){ Intlist=new ArrayList<>(); } Intlist.add("各项PWM数据:" + PGROME+" 0 0 0 0 0 0 ");//记录新的数据的同时还要保存原本的数据,可以接收到隔壁的main.Num } adpt=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,Intlist); //不知道怎么搞 LV.setAdapter(adpt); LV.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Toast.makeText(Activity2.this, "你点击了第"+i+"条", Toast.LENGTH_SHORT).show(); int Num_two= Integer.parseInt(Intlist.get(i)); Intent=new Intent(Activity2.this,MainActivity.class); //Intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //Intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent); } }); } public void add(View view) { BT2=findViewById(R.id.bt2); BT2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent=new Intent(Activity2.this,MainActivity.class); startActivity(Intent); } }); } public void empty(View view) { LV=findViewById(R.id.lv1); BT4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intlist=new ArrayList<>(); adpt=new ArrayAdapter<String>(Activity2.this, android.R.layout.simple_list_item_1,Intlist); LV.setAdapter(adpt); } }); } }
APP act2
最新推荐文章于 2024-08-16 10:12:43 发布