如何获取listView的特定TextView的所有值? -Android

时间:2016-09-05 12:21:48

标签: android listview

我已经使ListView有三列'item','qty','rate'我从用户那里得到这些条目并且我已经使listview完美地工作但我想获得'rate'列的所有值并为净额添加它们。

这是我的android代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    populateList();
    adapter = new listviewAdapter(List.this, list);
    lview.setAdapter(adapter);
}


private void populateList() {
    HashMap temp = new HashMap();
    list = new ArrayList<HashMap>();

    item = etItem.getText().toString();
    qty = etQty.getText().toString();
    rate = etRate.getText().toString();

    temp.put(FIRST_COLUMN, "1");
    temp.put(SECOND_COLUMN, item);
    temp.put(THIRD_COLUMN, qty);
    temp.put(FOURTH_COLUMN, rate);
    list.add(temp);

}

我尝试了下面这个方法,但它只干了第一个值。但我想获得费率列下的所有值,并将它们加到净额中。

   public void get() {
       StringBuilder sb = new StringBuilder();
       for(int i=0; i<adapter.getCount(); i++) {
           String a = ((TextView) findViewById(R.id.FourthText)).getText().toString();
           adapter.getItem(i).toString();
           sb.append(a);
           sb.append("\n");
       }
       text = sb.toString();
       Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
   }

2 个答案:

答案 0 :(得分:1)

function bulkXml() {
    var sheet = SpreadsheetApp.getActiveSheet();
    var Num = Browser.inputBox("How many URLs do you need to scrape?");

    for (x=2; x-2 < Num; x++)  {
        var url = sheet.getRange(x,1).getValue();
        sheet.getRange(2,6).setValue(url);
        var xpathResult = sheet.getRange(3,6).getValue();    
        var counter = x - 1;
        sheet.getRange("C4").setValue(counter + "/" + Num);
        sheet.getRange(x,2).setValue(xpathResult);
    }
}

答案 1 :(得分:0)

我认为这可能会对你有帮助。

private int GrandTotal(ListView list) {
int sum=0;
for (int i = 0; i < list.getCount(); i++) {
    View v = list.getChildAt(i);
    TextView rate = (TextView) v.findViewById(R.id.rate);
    sum = sum + Integer.parseInt(rate.getText().toString() )
}
return sum;

}

:)