Reputation: 1054
For my program in Android I want to use simple ArrayAdapter, without overriding the ArraYAdapter class. The problem is that the adapter is not being showed on the activity.
ArrayList<String> myList = generateListAndTaskText(intent);
final ListView myListView = (ListView) findViewById(R.id.widget_show_task_act_subtasks_listview);
Log.d("ShowTaskAct", myList.size() + ""); //Log shows 2 items
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
R.layout.main_child_item_lay,R.id.main_child_item_text, myList);
myListView.setAdapter(adapter);
Am I missing something here?
EDIT: The layout (simplified):
<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"
android:background="@android:color/transparent">
<TextView
android:id="@+id/widget_show_task_act_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Loading..."
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp" />
<ListView
android:id="@+id/widget_show_task_act_subtasks_listview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/widget_show_task_act_text" />
EDIT2: I forgot to tell you guys that the Activity is started from a screen widget. Thus should I use getApplicationContext() or getBaseContext() ?
Upvotes: 0
Views: 52
Reputation: 1054
Problem solved: static height for the listview does the job.
Upvotes: 0
Reputation: 5589
You are missing the bottom constraint for the Listview, and the height is 0.
For the ListView, contraint the bottom to the bottom of parent or some other widget that is already constrained.
Upvotes: 1
Reputation: 1153
try like below:
ArrayAdapter<String> adapter = new ArrayAdapter<String> (getBaseContext(),
android.R.layout.simple_dropdown_item_1line, myList);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
myListView.setAdapter(adapter);
Upvotes: 0