I've been stuck on this for a while. Right now when I input information in my input activity, the information gets displayed in the RecyclerView interface. However, when I input information a second time instead of making a 2nd row and displaying the information, it just replaces the original row that was created. I want it so it makes a new row each time new information is inputted. Any suggestions on what to do? This is my current code:
public class MainActivity extends AppCompatActivity { private RecyclerView mRecyclerView; private RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager mLayoutManager; private ArrayList<medicationinfo> mMedInfoList = new ArrayList<medicationinfo>(); private Button btnaddmed; private String med; private String time; private String pillnumber; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Bundle bundle = getIntent().getExtras(); if(bundle!=null) { med = bundle.getString("medItem"); time = bundle.getString("timeformed"); pillnumber = bundle.getString("pillnumber"); } createMedList(); buildRecyclerView(); btnaddmed = findViewById(R.id.addButton); btnaddmed.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent= new Intent(MainActivity.this,AddMed.class); startActivity(intent); } }); } public void createMedList() { mMedInfoList.add(new medicationinfo(med,time,pillnumber)); } public void buildRecyclerView() { mRecyclerView = findViewById(R.id.recyclerView); mRecyclerView.setHasFixedSize(true); mLayoutManager = new LinearLayoutManager(this); mAdapter = new MedicationAdapter(mMedInfoList); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); } }
https://stackoverflow.com/questions/65818256/on-android-studio-how-to-make-arraylist-receive-info-from-different-activity-an January 21, 2021 at 05:55AM
没有评论:
发表评论