응용 프로그램에서 간단한 항목 목록 (이 경우 이름)을 만들고 싶습니다. 저는 Android Studio를 사용하고 있습니다. 내가 아는 한 올바르게 모든 것을 작성했으며 어디에서 잘못되었는지 알지 못합니다.Android Studio에서 내 목록이 채워지지 않는 이유는 무엇입니까?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.scott.exampleapp.test_page">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list_view"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
그리고 내 해당 자바 파일 : 여기 내 XML
파일의
package com.example.scott.exampleapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class test_page extends AppCompatActivity {
String[] exampleArray = new String[]{"Scott", "Steffi", "Liam", "Jonny", "Zac"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_page);
ListView listView = (ListView) findViewById(R.id.list_view);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_test_page, exampleArray);
listView.setAdapter(adapter);
}
}
사용'android.R.layout을 .simple_list_item_1''ArrayAdapter() 내부의'R.layout.activity_test_page' 대신 –