[英]How can I loop thru a listview and getting the text from textviews in each row
我已經有了這個自定義的listview,並且想循環遍歷,從每一行的textview獲取文本。 這是我的代碼的本質:
private TextView totalColumn;
totalColumn = (TextView)findViewById(R.id.column3);
listView.setAdapter(adapter);
for(int i = 0; i < listView.getCount(); i++){
String p = totalColumn.getText().toString();
System.out.println(p);
}
我看不到我在做什么syso給了我一個Nullpointer。 getCount()= 4,所以那不是問題。
誰能幫我?
當空指針到達不存在的數組插槽時,可能會給出空指針。 嘗試
int i=0; i < shoppingL.size(); i++
要從列表視圖的文本視圖中獲取所有文本是錯誤的方法,因為列表視圖中可能有更多項目,然后才可見。 正確的方法是從適配器檢索文本。
你不能這樣做。 Listview包含當前正在查看的行。 不能一次創建所有行。 您可以從以下位置保存創建的視圖
公共View getView(int位置,View convertView,ViewGroup父級){}
回調方法。
並保存在集合(Arraylist)中,然后轉到列表視圖的末尾並迭代該集合,您將得到結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.