-1

At the moment I'm interested in developing my own android app.
Therefore I wanted to work with a ListView.

Actually my test-application crashes right after the start. I hope you can help me with it.

MainActivity.java

public class MainActivity extends ListActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String[] liste = {"Adidas","Nike","Puma"};
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,liste);
        ListView list=(ListView)findViewById(R.id.list);
        list.setAdapter(adapter);

    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="de.phxlxp_mxyxr.listview.MainActivity">


    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal" />

</android.support.constraint.ConstraintLayout>

2 Answers2

0
<ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:scrollbars="vertical" />

Please try with this.

PRATEEK BHARDWAJ
  • 2,364
  • 2
  • 21
  • 35
0

Rename the id of your ListView by android:id="@android:id/list".

Answer was here

<ListView
    android:id=android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal" />
Thomas Mary
  • 1,535
  • 1
  • 13
  • 24
  • If you think another question already has the answer, then please just flag the current one as a duplicate. Please don't answer duplicates. – Mike M. Jan 13 '18 at 18:09
  • 1
    I was not sure about this. Thanks :) Do you just need to add [duplicate] in title ? @MikeM. – Thomas Mary Jan 13 '18 at 18:11
  • 1
    I was just reviewing my comments, and saw that you'd edited yours. No, you don't want to edit the title. Use the _flag_ link under the question's tags. There you will find an option to select a post as a possible duplicate. – Mike M. Jan 17 '18 at 11:01