ListView项目文本是不可见的

问题描述 投票:-1回答:1

我的listview正在被光标填充,我可以看到listview行的轮廓,但每个listview项的文本都是空白的。我有一个点击监听器,它使用Toast信息显示listview项目并且它有效。这就像listview的文本颜色与背景使文本不可见相同,但我不确定这是什么问题。

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:layout_marginTop="5dp"
    android:text="Enter Data"
    android:onClick="onClickEnterData"/>
</LinearLayout>

sing_row_data.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TextView android:id="@+id/txtRecid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="Sample Data"
    android:textSize="15sp"
    android:paddingBottom="5dp"
    android:textColor="#fff" />

<TextView android:id="@+id/txtUnitid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="Sample Data 2"
    android:textSize="15sp"
    android:paddingBottom="5dp"
    android:textColor="#fff" />
</LinearLayout>

main activity.Java:

package com.example.listviewcontroler;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.example.listviewcontroler.R;

public class MainActivity extends AppCompatActivity {
MyActivity MA = new MyActivity() ;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MA.displayList() ;
    }
}

container_for_listview.xml:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/eq_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
android android-listview
1个回答
0
投票

除了与XML相关的问题之外,您还在为listView使用预先设计的行,但是您将四个项目传递给它。它不会那样工作。由于要在每行中显示四个文本,因此必须创建自定义行,然后将该布局传递给适配器。

我知道有一个预先设计的行,如下面的两个项目,但不知道是否有4个!

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
    android.R.layout.simple_list_item_2, 
    db.getAllTitles(), 
    new String[] { "first", "second" }, 
    new int[] { android.R.id.text1, android.R.id.text2 });
© www.soinside.com 2019 - 2024. All rights reserved.