Java 从ArrayList HashMap中的键/值检索值<;字符串,字符串>;

Java 从ArrayList HashMap中的键/值检索值<;字符串,字符串>;,java,android,arraylist,Java,Android,Arraylist,我已将一些值存储到ArrayList HashMap中,如下所示: ArrayList<HashMap<String, String>> bookDetails = new ArrayList<HashMap<String, String>>(); HashMap<String, String> map = new HashMap<String, String>(); map.put("b

我已将一些值存储到ArrayList HashMap中,如下所示:

ArrayList<HashMap<String, String>> bookDetails = new ArrayList<HashMap<String, String>>();

HashMap<String, String> map = new HashMap<String, String>();

                map.put("book_author", bookAuthor);
                map.put("book_description", bookDescription);


                bookDetails.add(map);
ArrayList bookDetails=new ArrayList();
HashMap=newHashMap();
地图放置(“图书作者”,图书作者);
地图放置(“书籍描述”,书籍描述);
添加(地图);

我只是希望能够检索描述值并将其显示在文本视图中,我将如何进行此操作?提前感谢。

类似的方法应该可以:

TextView text = (TextView) findViewById(R.id.textview_id);
text.setText(bookDetails.get(0).get("book_description"));

除了调用
get(0)
之外,您当然还可以迭代
bookDetails
数组并获取当前的迭代计数器变量,例如
get(n)
真的需要映射吗?

为什么不创建一个Book.java对象呢

图书对象有两个属性:

public class Book {

    private String bookAuthor;
    private String bookDescription;

    public String getBookAuthor() {
        return bookAuthor;
    }
    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }
    public String getBookDescription() {
        return bookDescription;
    }
    public void setBookDescription(String bookDescription) {
        this.bookDescription = bookDescription;
    }

}

然后你可以有一个图书列表

我建议改变你存储信息的方式

若地图只包含作者和描述,一个有效的方法是完全省略ArrayList,只使用地图

地图将是

HashMap<String, String> map;
map.put(bookAuthor, bookDescription);
希望这有帮助

String desc = map.get(bookAuthor);