Android 无法显示阵列适配器项,它采用背景色

Android 无法显示阵列适配器项,它采用背景色,android,Android,我让列表项包括2个文本视图和一个图像视图,但所有项都显示为相同的背景颜色,尽管我试图在数组适配器中强制更改颜色,但没有更改 活动\u main.xml代码是: ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list" android:orientation="vertical" androi

我让列表项包括2个
文本视图
和一个
图像视图
,但所有项都显示为相同的背景颜色,尽管我试图在数组适配器中强制更改颜色,但没有更改 活动\u main.xml代码是:

ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"/>
列表项.xml

<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="@dimen/list_item_height"
    android:background="@color/tan_background"
    android:minHeight="@dimen/list_item_height">

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/list_item_height"
        android:layout_height="@dimen/list_item_height" />

    <RelativeLayout
        android:id="@+id/text_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/list_item_height"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/image"
        android:orientation="vertical"
        android:paddingLeft="16dp">

        <TextView
            android:id="@+id/miwok_text_view"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:layout_weight="1"
            android:gravity="bottom"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            tools:text="lutti" />

        <TextView
            android:id="@+id/default_text_view"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:layout_below="@id/miwok_text_view"
            android:layout_weight="1"
            android:gravity="top"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white"
            tools:text="one" />


    </RelativeLayout>
</RelativeLayout>

主要活动代码为

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the content of the activity to use the activity_main.xml layout file
        setContentView(R.layout.activity_main);
 final ArrayList<Word> words = new ArrayList<Word>();
        words.add(new Word(R.string.category_alphabet, R.string.empty_string,
                R.drawable.alphabet, R.raw.sixty));
        words.add(new Word(R.string.category_numbers, R.string.empty_string,
                R.drawable.numbers, R.raw.seventy));
        words.add(new Word(R.string.category_colors, R.string.empty_string,
                R.drawable.colors, R.raw.eighty));
        words.add(new Word(R.string.category_family, R.string.empty_string,
                R.drawable.family, R.raw.ninty));
 FirstPageAdapter adapter = new FirstPageAdapter(this, words, R.color.try_under_color);

        // Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
        // There should be a {@link ListView} with the view ID called list, which is declared in the
        // word_list.xml layout file.
        ListView listView = (ListView) findViewById(R.id.list);

        // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
        // {@link ListView} will display list items for each {@link Word} in the list.

        listView.setAdapter(adapter);
 listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Word word = words.get(i);
                if( word.getDefaultTranslationId()==R.string.category_alphabet){


                    Intent alphabetsIntent = new Intent(MainActivity.this, AlphabetsActivity.class);

                    // Start the new activity
                    startActivity(alphabetsIntent);

                }
                else if( word.getDefaultTranslationId()==R.string.category_numbers){

                    Intent numbersIntent = new Intent(MainActivity.this, NumbersActivity.class);

                    // Start the new activity
                    startActivity(numbersIntent);

                }

            }
        });


    }



}
public类MainActivity扩展了AppCompatActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//设置活动的内容以使用activity_main.xml布局文件
setContentView(R.layout.activity_main);
最终ArrayList单词=新ArrayList();
words.add(新词(R.string.category_字母表、R.string.empty_字符串、,
R.可绘制字母表,R.原始字母表(60);
words.add(新词(R.string.category\u number,R.string.empty\u string,
R.drawable.number,R.raw.70);
添加新词(R.string.category\u颜色,R.string.empty\u字符串,
R.可绘制颜色,R.原始颜色(80);
words.add(新词(R.string.category_family,R.string.empty_string,
R.drawable.family,R.raw.ninty);
FirstPageAdapter=新的FirstPageAdapter(this,words,R.color.try\u在\u颜色下);
//在{@link Activity}的视图层次结构中查找{@link ListView}对象。
//应该有一个{@link ListView},其视图ID为list,在
//word_list.xml布局文件。
ListView ListView=(ListView)findViewById(R.id.list);
//使{@link ListView}使用我们在上面创建的{@link WordAdapter},以便
//{@link ListView}将显示列表中每个{@link Word}的列表项。
setAdapter(适配器);
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
公共无效onItemClick(AdapterView AdapterView、View视图、int i、long l){
单词=words.get(i);
if(word.getDefaultTranslationId()==R.string.category_字母表){
意向字母表意向=新意向(MainActivity.this,AlphabetsActivity.class);
//开始新的活动
星触觉(字母);
}
else if(word.getDefaultTranslationId()==R.string.category\u编号){
Intent numbercontent=新的Intent(MainActivity.this、numberActivity.class);
//开始新的活动
起始触觉(数字内容);
}
}
});
}
}

我不知道如何显示列表项的内容

我通过添加 View=listItemView.getRootView(); 视图。setBackgroundColor(颜色); 但在文本视图不出现的地方出现了一个新问题,即如何显示文本视图的内容