簡體   English   中英

如何從 ListView 獲取項目並將這些項目轉換為 ArrayList?

[英]How can I get the items from a ListView and convert these items to an ArrayList?

如何從 ListView 獲取項目並將它們轉換為ArrayList

https://i.stack.imgur.com/kWHzT.png

截圖:(在mConversationArrayAdapter中必須是 go 的arraylist)

您必須在適配器中創建一個獲取 arrayList 的方法,然后在需要數據的地方調用該方法。

像這樣的東西,

 public ArrayList<String> getData(){ return this.arrayList; }

您必須在適配器中創建一個方法來獲取如下值:

public Object getItem(int position) {
        return mConversationArrayAdapter.get(position);
    }

或者直接在您的 class 中獲取它們。

但是如果要顯示列表,就必須使用“ RecyclerView ”,效果比ListView好。

你應該這樣嘗試。

ListView listView = new ListView();

    listView.getItems().add("Item1;");
    listView.getItems().add("Item;2");
    listView.getItems().add("Item3;");

     for (int i=0;i<listView.getItems().size();i++){
         String currentLine= (String) listView.getItems().get(i);
         String[] cells=currentLine.split(";");
         System.out.println(currentLine);
         System.out.println(Arrays.toString(cells));
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM