1

в Strings.xml содержится массив данных, которые нужно вывести в listview с названием creatorList. настройки ListView:

<ListView
        android:id="@+id/creatorList"
        android:textColor="#1031D3"
        android:layout_width="407dp"
        android:layout_height="635dp"
    app:layout_constraintBottom_toTopOf=&quot;@+id/version&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toBottomOf=&quot;@+id/Creator&quot; /&gt;

код в MainActivity.jar ListView creatorList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    buttonCreator = (Button) findViewById(R.id.buttonCreator);
    buttonCreator.setOnClickListener(this);
ListView creatorList = findViewById(R.id.creatorList);
String[] creator = getResources().getStringArray(R.array.creator);
ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;&gt;(this,
        android.R.layout.simple_list_item_1, creator);
creatorList.setAdapter(adapter);

}

данный ListView нужно привязать к Activity - Activity_creator.xml

Activiti_Main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
&lt;Button
    android:id=&quot;@+id/buttonStart&quot;
    android:layout_width=&quot;143dp&quot;
    android:layout_height=&quot;60dp&quot;
    android:text=&quot;Start&quot;
    app:backgroundTint=&quot;#1031D3&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot;
    app:layout_constraintVertical_bias=&quot;0.932&quot; /&gt;

&lt;Button
    android:id=&quot;@+id/buttonCreator&quot;
    android:layout_width=&quot;277dp&quot;
    android:layout_height=&quot;43dp&quot;
    android:text=&quot;Creator&quot;
    app:layout_constraintBottom_toTopOf=&quot;@+id/buttonStart&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot;
    app:layout_constraintVertical_bias=&quot;0.059&quot;
    app:backgroundTint=&quot;#1031D3&quot;

    /&gt;




</androidx.constraintlayout.widget.ConstraintLayout>

Активити на котором находится listview:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".Creator">
&lt;TextView
    android:id=&quot;@+id/Creator&quot;
    android:layout_width=&quot;252dp&quot;
    android:layout_height=&quot;39dp&quot;
    android:gravity=&quot;center&quot;
    android:text=&quot;Creator&quot;
    android:textColor=&quot;#1031D3&quot;
    android:textSize=&quot;25sp&quot;
    android:fontFamily=&quot;sans-serif-condensed&quot;


    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintHorizontal_bias=&quot;0.497&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot;
    app:layout_constraintVertical_bias=&quot;0.039&quot;

    /&gt;

&lt;TextView
    android:id=&quot;@+id/version&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:text=&quot;version 0.0.2&quot;
    android:textColor=&quot;#1031D3&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;

     /&gt;

&lt;ListView
    android:id=&quot;@+id/creatorList&quot;
    android:textColor=&quot;#1031D3&quot;
    android:layout_width=&quot;407dp&quot;
    android:layout_height=&quot;635dp&quot;

    app:layout_constraintBottom_toTopOf=&quot;@+id/version&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toBottomOf=&quot;@+id/Creator&quot; /&gt;


</androidx.constraintlayout.widget.ConstraintLayout>

Hramoff
  • 33
  • С текущим кодом проблем нет, покажите весь activity_main.xml (отредактируйте вопрос), может что с ConstraintLayout не так. – Vadik Sirekanyan Aug 03 '21 at 22:07
  • Еще нужно уточнение по поводу "Listview не выводит поля". Что вы видите на экране? Есть ли при этом ошибки в logcat? Добавьте эту информацию в вопрос. – Vadik Sirekanyan Aug 03 '21 at 22:56

1 Answers1

2

Ошибка заключается в том, что вы делаете findViewById(R.id.creatorList) в классе MainActivity.

Класс MainActivity соответствует разметке activity_main.xml, но в нем у вас нет вьюх с id creatorList.

ListView находится в другой активити, в ней и делайте findViewById(R.id.creatorList).