Android Listview does not appear

-3

The code does not give error, it shows in design mode, but does not appear the Listview populated. I'm using the example set up on the link

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

       <ListView
            android:id="@+id/listada"

            android:layout_width="380dp"
            android:layout_height="330dp"
            android:layout_marginTop="148dp"
            />
    </RelativeLayout>

</GridLayout>
public class ResultadosActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
        setContentView(R.layout.resultados);

        ListView lista = (ListView) findViewById(R.id.lista); //listada no real

        String[] strings = new String[] { "nome1", "nome2", "nome3", "nome4" };

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,strings);

        lista.setAdapter(adapter);

    }
}

results.xml , an illustrative XML that supports this view:

<LinearLayout>
    <ListView
        android:id="@+id/lista" />
</LinearLayout>

These two sections

    
asked by anonymous 10.05.2018 / 18:31

1 answer

0

@dandrade, I recommend you read about Spinner , I do not recommend to populate a list dynamic but for a static list and a few yes items. I encourage you to create and popular a ListView dynamic with an Adapter , so you have more control over the design items in the list.

Another thing, as colleague @Paulo Calado quoted and the documentation itself recommends, use the RecyclerView , you'll have a better performance on your list

I hope to have helped, hug.

    
14.05.2018 / 16:50