我开发了一个应用程序。在这里,我必须在ArrayList. 如果我必须点击Button意味着价值必须增加ArrayList。我必须单击另一个Button表示添加的列表正在显示。我能怎么做?请给我解决方案。
这些是我的价值观:
product_id = getIntent().getStringExtra("id");
product_title = getIntent().getStringExtra("title");
product_image = getIntent().getStringExtra("image");
product_price = getIntent().getStringExtra("price");
product_desc = getIntent().getStringExtra("description");
arrayList = new ArrayList<String>();
arrayList.add(product_title);
arrayList.add(product_price);
arrayList.add(product_id);
arrayList.add(product_image);
arrayList.add(product_desc);
Run Code Online (Sandbox Code Playgroud)
我必须ArrayList在单击时添加这些值Button:
valueaddlist = (Button) findViewById(R.id.valueaddlist);
valueaddlist.setOnClickListener(new OnClickListener() {
public void onClick(View v){
Intent intent = new Intent(this,AddedListProducts.class);
intent.putExtra("WishListProducts", arrayList);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
在AddedListProducts必须显示所有添加的产品列表中。
我能怎么做 ?请给我解决这些问题?
编辑:
这是我的 AddListProducts 类代码:
wishlist_products = (ListView) findViewById(R.id.wishlist_products);
if(getIntent().getExtras() !=null){
WishListProducts = (ArrayList<String>) getIntent().getExtras().getSerializable("WishListProducts");
System.out.println(WishListProducts); …Run Code Online (Sandbox Code Playgroud) 我有100 000个对象的数组列表。我想删除某些具有特定ID的对象。我正在使用for循环来搜索ArrayList和删除它们中的每一个。因此,这非常耗时。有没有任何可能的方法可以执行此操作而不会循环?
如何检查内部是否存在特定的字符串ArrayList<String[]>?
我是否需要迭代每个项目并检查字符串或为此目的的任何特定方法(如ArrayList.contains())?
尝试过 ArrayList.contains() 但在我的情况下不起作用。
这不是一个ArrayList <String>事实ArrayList<String[]>所以这个问题不是一个重复的问题,我问这个是为了好奇是否存在任何特殊方法
我有一个ArrayList,我需要在相反的方向重写它.怎么做?
List<Posts> viewList = new ArrayList<Posts>();
viewList = viewLogic.getPostsList(username);
Run Code Online (Sandbox Code Playgroud) 如果你的问题是我java.lang.ArrayIndexOutOfBoundsException在我的代码中得到了一个,我不明白为什么会发生这种情况.它是什么意思,我该如何避免它?
这是关于这个主题的最全面的Canonical信息集合
java.lang.ArrayIndexOutOfBoundsException以及java.lang.IndexOutOfBoundsException.
有很多像这样的问题,所有这些都有模糊的没有代码答案,或者大多数都非常具体,并且局限于手头的问题,并没有解决在所有情况下完全相同的根本原因.
如果您看到属于此一般情况的一个,而不是使用更多重复的专门内容回答它,请将其标记为此副本的副本.
arraylist ×5
java ×4
android ×2
loops ×2
arrays ×1
for-loop ×1
java-8 ×1
performance ×1
string ×1
while-loop ×1