【问题标题】:Android: Adding/Calling values from arrayAndroid:从数组中添加/调用值
【发布时间】:2011-06-23 17:10:48
【问题描述】:

我试图在单击按钮时将值存储到数组中,然后在存储到数组中后调用它。

这是我的数组代码:

public class Favorites extends ListActivity {
    static ArrayList<String> ItemArray = new ArrayList<String>();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Full Screen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.favorites);


    }


    public void add(String Item) {
        ItemArray.add(Item);


    }


}

这是我在按钮单击中的代码

String Item;
Item=getItem();

Bundle value= new Bundle();
value.putStringArrayList(Item, MyArrayClass.ItemArray);

【问题讨论】:

  • 对不起,它没有将值添加到数组中。

标签: android arrays


【解决方案1】:

不太清楚你在这里问什么,但如果你想在数组列表中添加一些东西,你会调用:

ItemArray.add(Item); 

就像您在 add 函数中一样,要从数组列表中获取值,请调用:

ItemArray.get(i);

其中 i 是您想要的项目的索引。 希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    相关资源
    最近更新 更多