0

The second activity has a ListView and it does not display it.

The Log.i in the UserList shows that the activity is active.

MainActivity.java:

public void makeUserListIntent() {
    Intent userListIntent = new 
      Intent(getApplicationContext(),UserList.class);
    startActivity(userListIntent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if ( ParseUser.getCurrentUser() != null ) makeUserListIntent();
}

UserList.java:

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

    Log.i("Second Activity: ", "onCreate");
    ListView listViewUserList = findViewById(R.id.listViewUserList);
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("Test User");
    arrayList.add("Test User");
    ArrayAdapter arrayAdapter = new 
       ArrayAdapter(this,android.R.layout.simple_list_item_1,arrayList);
    listViewUserList.setAdapter(arrayAdapter);
    listViewUserList.setVisibility(View.VISIBLE);
}

activiy_user_list.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=".UserList">

<ListView
    android:id="@+id/listViewUserList"
    android:layout_width="395dp"
    android:layout_height="715dp"
    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

I should see the ListView but a blank page appears.

The Log.i in the UserList.java shows that the activity gets called. Tried setting the visibility etc.

Why can't I see the ListView?

Prags
  • 2,457
  • 2
  • 21
  • 38
Zod
  • 87
  • 3

2 Answers2

0

The issue here is that you are setting the height to a a constant value 715dp, hence the first few items will not be visible on smaller devices. To fix this change your height to match_parent and add some margin at the top if that was your desired output

Oush
  • 3,090
  • 23
  • 22
0

Please Edit The activiy_user_list.xml Like This:

<?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=".UserList">

<ListView
    android:id="@+id/listViewUserList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="visible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44