How to get the value from ArrayList<Object> in android

austin

i have created a getter and setter class as follow:

public class LayoutClass {

private boolean layoutstatus;

    public void setlayoutStatus(boolean layoutstatus)
    {
        this.layoutstatus=layoutstatus;
    }
    public boolean getlayoutStatus()
    {
        return this.layoutstatus;
    }

    public void setlayoutstring(String layoutstring)
    {
        this.layoutstring=layoutstring;
    }
    public String getlayoutstring()
    {
        return this.layoutstring;
    }
}

and a class for store data in arraylist as given below:

public class LayoutListClass {
     public static final ArrayList<LayoutClass> layoutList = new ArrayList<LayoutClass>();

}

i have added the value in a activity as folow:

LayoutClass layoutobj=new LayoutClass();
layoutobj.setlayoutstring("test1");
layoutobj.setlayoutStatus(true);
LayoutListClass.layoutList.add(layoutobj);      

layoutobj.setlayoutstring("test2");
layoutobj.setlayoutStatus(true);
LayoutListClass.layoutList.add(layoutobj);


layoutobj.setlayoutstring("test3");
layoutobj.setlayoutStatus(false);
LayoutListClass.layoutList.add(layoutobj);

and when i am going to get the value:

for(LayoutClass layoutobj:LayoutListClass.layoutList)
            {
                Log.i("Layout "+g,"->"+layoutobj.getlayoutstring()+" Status = "+layoutobj.getlayoutStatus());

            }

i am only able to getting the last value "test3" all three times.

i want to know how to get the proper value or how to store the object of arraylist and used it later.

Lakhwinder Singh
LayoutClass layoutobj=new LayoutClass();
layoutobj.setlayoutstring("test");
layoutobj.setlayoutStatus(true);

LayoutClass layoutobj1=new LayoutClass();
layoutobj1.setlayoutstring("test1");
layoutobj1.setlayoutStatus(true);

LayoutClass layoutobj2=new LayoutClass();
layoutobj2.setlayoutstring("test2");
layoutobj2.setlayoutStatus(false);

LayoutListClass.layoutList.add(layoutobj);
LayoutListClass.layoutList.add(layoutobj1);
LayoutListClass.layoutList.add(layoutobj2);

Do it like this.

Why you are getting the last value, because you are changing the value of a single object you need to create object for every position in Arraylist

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android how to savestate arraylist

来自分类Dev

How to get a value from keyvalue pair list?

来自分类Dev

Java ArrayList get()作为Integer而不是Object

来自分类Dev

如何从android中的ArrayList <Object>获取值

来自分类Dev

How to get a filename from an ImageView (ANDROID)

来自分类Dev

How to get time from Network in Android

来自分类Dev

How to get name of the object's from a different class in Java

来自分类Dev

Get value of object literal key

来自分类Dev

How to get a value from CV_8UC4 matrix

来自分类Dev

How do I get a value from an associative array using Swift

来自分类Dev

How to get a single value from gae ndb query?

来自分类Dev

How to get value from Future with custom model in flutter

来自分类Dev

Android将ArrayList <Object>保存为SharedPreference

来自分类Dev

将ArrayList <Object>传递回主活动(Android)

来自分类Dev

将ArrayList <object>添加到listview -android

来自分类Dev

Android : How to get the Id of selected item from Spinner

来自分类Dev

how to take a single record from an arraylist in mongodb

来自分类Dev

How to get text value from radio button and assign value to a specific div

来自分类Dev

How to get a value which is a list from redis key-value store in golang?

来自分类Dev

Ajax get value from php

来自分类Dev

How to use associate arrays to get the id from the checkbox and appropreate value from the text field

来自分类Dev

How can my data object reject changes from a databound control? (Control is not displaying actual value)

来自分类Dev

无法将 ArrayList<ArrayList<Integer>> 转换为 ArrayList<ArrayList<Object>>

来自分类Dev

Get JSON objects from a JSON object

来自分类Dev

使用 JSON 按条件定义组或元素填充 ArrayList<ArrayList<Object>>(尝试为 Android 中的可扩展列表创建数据)

来自分类Dev

ArrayList <Object>中的ConcurrentModificationException

来自分类Dev

ArrayList转换为Object [] []

来自分类Dev

从ArrayList <object>获取对象

来自分类Dev

Modify value in ArrayList

Related 相关文章

  1. 1

    Android how to savestate arraylist

  2. 2

    How to get a value from keyvalue pair list?

  3. 3

    Java ArrayList get()作为Integer而不是Object

  4. 4

    如何从android中的ArrayList <Object>获取值

  5. 5

    How to get a filename from an ImageView (ANDROID)

  6. 6

    How to get time from Network in Android

  7. 7

    How to get name of the object's from a different class in Java

  8. 8

    Get value of object literal key

  9. 9

    How to get a value from CV_8UC4 matrix

  10. 10

    How do I get a value from an associative array using Swift

  11. 11

    How to get a single value from gae ndb query?

  12. 12

    How to get value from Future with custom model in flutter

  13. 13

    Android将ArrayList <Object>保存为SharedPreference

  14. 14

    将ArrayList <Object>传递回主活动(Android)

  15. 15

    将ArrayList <object>添加到listview -android

  16. 16

    Android : How to get the Id of selected item from Spinner

  17. 17

    how to take a single record from an arraylist in mongodb

  18. 18

    How to get text value from radio button and assign value to a specific div

  19. 19

    How to get a value which is a list from redis key-value store in golang?

  20. 20

    Ajax get value from php

  21. 21

    How to use associate arrays to get the id from the checkbox and appropreate value from the text field

  22. 22

    How can my data object reject changes from a databound control? (Control is not displaying actual value)

  23. 23

    无法将 ArrayList<ArrayList<Integer>> 转换为 ArrayList<ArrayList<Object>>

  24. 24

    Get JSON objects from a JSON object

  25. 25

    使用 JSON 按条件定义组或元素填充 ArrayList<ArrayList<Object>>(尝试为 Android 中的可扩展列表创建数据)

  26. 26

    ArrayList <Object>中的ConcurrentModificationException

  27. 27

    ArrayList转换为Object [] []

  28. 28

    从ArrayList <object>获取对象

  29. 29

    Modify value in ArrayList

热门标签

归档