我正在尝试使用ArrayAdapter在ListView中显示数组项。它没有在ListView中显示任何项目,也没有显示任何错误,下面是我的java类和xml。
package church.llagc.com;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class listView extends AppCompatActivity {
ArrayAdapter<String> adapter;
String[] alphabitlist = {"A","Aa","I","EE","U","Uu","E","EI","O","Oo","Ka","Ga","Cha","Ja","Tha","Da","Na","Pa","Ba",
"Bha","Ma","Ya","Ra","La","Va","Ssa","Sha","Sa","Ha"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,alphabitlist);
ListView alpabits = (ListView) findViewById(R.id.alphabitorder);
alpabits.setAdapter(adapter);
}
}
containt_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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="church.llagc.com.MainActivity"
tools:showIn="@layout/app_bar_main">
<include layout="@layout/activity_list_view"/>
</android.support.constraint.ConstraintLayout>
和我的activity_list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
tools:context="church.llagc.com.listView">
<ListView
android:background="@drawable/alphabit_bg"
android:id="@+id/alphabitorder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scrollbars="none"/>
<ListView
android:id="@+id/itemcontent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"/>
</LinearLayout>
如果您有任何疑问,请发表评论。
答案 0 :(得分:0)
试试这个。
<ListView
android:background="@drawable/alphabit_bg"
android:id="@+id/alphabitorder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:scrollbars="none"/>
<ListView
android:id="@+id/itemcontent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"/>
</LinearLayout>
答案 1 :(得分:0)
不要使用android.R.layout.simple_list_item_1
并创建自己的布局文件。这个android.R.layout.simple_list_item_1
布局文件有一个简单的text view
,但文字颜色与白色有关,这就是你无法看到它的原因。现在,您必须创建一个仅包含text view
并设置text color
的新布局文件,并将其传递给您的适配器