gpt4 book ai didi

Android Gallery 纯文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:18:12 25 4
gpt4 key购买 nike

我查看了 API 演示,他们有一个画廊示例,其中仅显示文本,代码仅使用 Cursor ,但我想使用 String 数组。我怎样才能实现使用它?这是 API 演示中示例的代码:

        Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(c);

SpinnerAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_gallery_item,
// Give the cursor to the list adatper
c,
// Map the NAME column in the people database to...
new String[] {People.NAME},
// The "text1" view defined in the XML template
new int[] { android.R.id.text1 });

最佳答案

如果你只想显示一个String对象的静态列表,一个ArrayAdapter应该做的:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new String[] {People.NAME});

但是,如果您希望稍后能够将更多的 String 对象添加到列表中,您应该使用 List

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, new ArrayList<String>());

关于Android Gallery 纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1695512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com