遍历ListView和获得的EditText字段值 [英] Iterate through ListView and get EditText-Field values

查看:586
本文介绍了遍历ListView和获得的EditText字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个ListView(myList上)有一个EditText上,现场的每一行中(R.id.mannschaften)。在ListView中,我创建了一个按钮,并在OnCreate()设置一个OnClickListener它 - 法。 现在,按钮被点击时,我想遍历ListView,并且让每一个行中的EditText字段的值,并将其保存在一个字符串列表。但我怎么做呢?

I've created a ListView (myList) with one EditText-Field in each row (R.id.mannschaften). Under the ListView, I've created a Button and set an OnClickListener for it in the OnCreate()-Method. Now when the Button is clicked, I want to iterate through the ListView and get the value of the EditText-Field in every row and save them in a String-List. But how do I do that?

下面是我的code:

private void ButtonClick() {
    /** get all values of the EditText-Fields */
    View v;
    ArrayList<String> mannschaftsnamen = new ArrayList<String>();
    EditText et;

    for (int i = 0; i < myList.getCount(); i++) {
        v = myList.getChildAt(i);
        et = (EditText) v.findViewById(R.id.mannschaften);
        mannschaftsnamen.add(et.getText().toString());
    }
    .....
}

我已经知道了,那getChildAt只对可见的行,但我不知道如何以不同的做到这一点。

I already know, that getChildAt is only for the visible rows, but I don't know how to do it differently.

推荐答案

解决了这个问题与一个朋友的帮助:

Solved the Problem with the help of a friend:

private void ButtonClick() {
    /** get all values of the EditText-Fields */
    View v;
    ArrayList<String> mannschaftsnamen = new ArrayList<String>();
    EditText et;
    for (int i = 0; i < myList.getCount(); i++) {
        v = myList.getAdapter().getView(i, null, null);
        et = (EditText) v.findViewById(i);
        mannschaftsnamen.add(et.getText().toString());
    }
....
}

这篇关于遍历ListView和获得的EditText字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆