Listview for Arraylist

Asked

Viewed 150 times

0

I have a Listview, one EditText and a Buttom. When I click on the button I want it to play what it has on ListView in a ArrayList, so that I can enter what was written in the EditText in the ArrayList and then use it to carry the ListView.

In short, that would be:

ArrayList = ListView;
ArrayList.add(valor);
ListView.setAdapter(new ArrayAdapter(this, ..., ArrayList));

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal" >

    <ImageButton
        android:id="@+id/imgBtIncluirPessoaTarefa"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/edtPessoaEditarTarefa"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@android:drawable/ic_input_add" />

    <EditText
        android:id="@+id/edtPessoaEditarTarefa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/imgBtIncluirPessoaTarefa"
        android:ems="10"
        android:hint="Pessoa"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ListView
        android:id="@+id/listaPessoasEditar"
        android:layout_width="match_parent"
        android:layout_height="130sp" >
    </ListView>
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal" >

    <ImageButton
        android:id="@+id/imgBtIncluirTarefa"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/edtTarefaEditarTarefa"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@android:drawable/ic_input_add" />

    <EditText
        android:id="@+id/edtTarefaEditarTarefa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/imgBtIncluirTarefa"
        android:ems="10"
        android:hint="Tarefa"
        android:inputType="textPersonName" >
    </EditText>
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ListView
        android:id="@+id/listaTarefasEditar"
        android:layout_width="match_parent"
        android:layout_height="130sp" >
    </ListView>
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
</RelativeLayout>

  • Where that Button is? Want to get the whole list or just a line? If it’s a line, how do you know the line?

  • I want to get all the lines!

  • Could include your layout?

  • it seems that it returns an Adapter, but error to convert to arrayList

  • 1

    You want the value that’s in Adapter or the current value of the list items? It is possible to iterate over the Adapter and use the getItem, since unfortunately the ArrayAdapter does not provide access to the list directly. But by accessing getItem, you are accessing the values you used to popular the elements and not the current.

  • I want to take what’s in Listview!

  • Got it @Césaralves, I will try to prepare an answer as soon as I have less curled up, even today.

  • I could do it here bro! Thank you so much! @Wakim

  • if you can, put the code you solved as a question and accept it, it can help other people who might have this problem.

  • @Césaralves Consider posting the solution to this problem and help others with it.

  • I just gave a getAdapter() and inserted the String into the returned Adapter. Then I gave a notifyChange...(). Success! Vlw to everyone!

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.