遍历ListView和获得的EditText字段值遍历、字段、ListView、EditText

由网友(时光取名叫无心)分享简介:我已经创建了一个ListView(myList上)有一个EditText上,现场的每一行中(R.id.mannschaften)。在ListView中,我创建了一个按钮,并在OnCreate()设置一个OnClickListener它 - 法。现在,按钮被点击时,我想遍历ListView,并且让每一个行中的EditT...

我已经创建了一个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());
    }
....
}
阅读全文

相关推荐

最新文章