加载字符串数组时为什么listview显示为黑色?

时间:2014-06-08 08:01:39

标签: android listview arrays

我从string.xml将3个字符串数组加载到listview中。在屏幕大于5英寸的设备中,它根据需要显示,但是对于具有较小屏幕尺寸的设备,它显示为黑色。可能是什么问题??

我的Java代码:

package com.newlife.starts;

import com.newlife.starts.adapter.MyCustomAdapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;

public class Info extends Activity {
    ListView lv;
    MyCustomAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.placesinfo);
        lv = (ListView) findViewById(R.id.listView1);
        String[] items1 = getResources().getStringArray(R.array.gwara);
        String[] items2 = getResources().getStringArray(R.array.place);
        String[] items3 = getResources().getStringArray(R.array.taal);

        adapter = new MyCustomAdapter(getApplicationContext(), items1, items2,
                items3);
        lv.setAdapter(adapter);

    }

    @Override
    public boolean onCreateOptionsMenu(android.view.Menu menu) {
        MenuInflater blowUp = getMenuInflater();
        blowUp.inflate(R.menu.about, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {

        case R.id.about:

            Intent i = new Intent(Info.this, About.class);
            startActivity(i);

        }
        return false;
    }
}

我的XML代码:

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

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:stretchColumns="*" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/ttyyborder" >

            <TextView
                android:id="@+id/gwara"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="ग्वारा "
                android:textColor="#FFFFFF"
                android:textSize="22sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/place"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="थाय्"
                android:textColor="#FFFFFF"
                android:textSize="22sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/taal"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="ताल"
                android:textColor="#FFFFFF"
                android:textSize="22sp"
                android:textStyle="bold" />
        </TableRow>
    </TableLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tableLayout1"
        android:layout_centerHorizontal="true" >
    </ListView>

</LinearLayout>

3 个答案:

答案 0 :(得分:0)

更改您的代码并查看:

<ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tableLayout1"
        android:background="#FFFFFF"
        android:layout_centerHorizontal="true" >
</ListView>

答案 1 :(得分:0)

试试这个:

<ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tableLayout1"
        android:layout_centerHorizontal="true"
        android:cacheColorHint="@android:color/transparent" >
</ListView>

我猜问题包含自定义背景颜色的ListView(here explains this problem),透明颜色应该修复它

答案 2 :(得分:0)

实际上textview的背景导致了这个问题。我修改了后台文件(xml文件)

来自

<stroke
android:width="1dp"
android:color="#000000" />

<stroke
android:width="1dp"
android:color="#FF000000" />

<solid android:color="#00FFFFFF" />