i have a problem in storing the Item in the Array List here is my Code
package com.example.java;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;
import org.w3c.dom.Element;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
public class MainActivity3 extends AppCompatActivity {
private static final String Tag = "MainAcitivity3";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Log.d(Tag, "onCreate: Started.");
ListView mListView = (ListView) findViewById(R.id.listView);
Intent intent = getIntent();
String asd = intent.getStringExtra(MainActivity2.namabarang);
String asdf = intent.getStringExtra(MainActivity2.jumlahstock);
Item sparepart = new Item(asd,asdf);
ArrayList<Item> itemlist = new ArrayList<Item>();
itemlist.add(sparepart);
PersonListAdapter adapter = new PersonListAdapter(this, R.layout.adapter_view_layout,itemlist);
mListView.setAdapter(adapter);
String number = intent.getStringExtra(MainActivity2.extraint);
if(number != null) {
FrameLayout lay = (FrameLayout) findViewById(R.id.frames);
if (number.equals("1")) {
lay.setVisibility(View.INVISIBLE);
mListView.setVisibility(View.VISIBLE);
} else {
}
}
else{}
}
public void onBtnClick (View view){
Intent intent = new Intent(this,MainActivity2.class);
startActivity(intent);
}
}
What i try to do is the the storing of item in the itemlist will be inform of automation through the array numbering. Therefore i will add the looping in the itemlist to store the item but the problem is when i want to make it into ArrayList[] itemlist = new ArraList[]; There is an error.
So what im tryna do is
public void onCreate(){
int loop=0;
loop++;
String asd = intent.getStringExtra(MainActivity2.namabarang);
String asdf= intent.getStringExtra(MainActivity2.jumlahstock);
Item sparepart = new Item(asd,asdf);
ArrayList<item>[] itemlist= new ArrayList[]();
itemlist[loop] = sparepart;
}
So that everytime the MainActivity3 running it does save string in array 0, and then running in another Activity, when back to the MainActivity3 the string will save in Array 1. Please the help