android - 我如何在我的 Android 应用程序中看到完整的 ListView

标签 android listview android-intent android-arrayadapter listadapter

我写作是为了使用 ListView 测试 Android 应用程序。这个 ListView 我用 ListAdapter 填充,它工作正常。只有当我启动应用程序时,我才看不到完整的 ListView :(

enter image description here

这是我的activity_main.xml

<?xml version="1.0" encoding="utf-8" ?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical">

   <ListView
       android:id="@+id/listview1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       ></ListView>

</LinearLayout>

这是我的 MainActivity.java

package de.linde.listview;

import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        List valueList = new ArrayList<String>(); 

        for(int i=0;i<10;i++)
        {
            valueList.add("value" + i); 
        }

        ListAdapter adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,valueList); 

        final ListView lv = (ListView)findViewById(R.id.listview1);
        lv.setAdapter(adapter); 
    }

}

我做错了什么:(?

最佳答案

您的文字颜色有问题。

尝试更改 ListView 的文本颜色或背景颜色。肯定会起作用。

  <ListView
   android:background="#C0C0C0" <------
   android:id="@+id/listview1"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content">
   </ListView>

关于android - 我如何在我的 Android 应用程序中看到完整的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12835521/

相关文章:

android - DDMS 和虚拟创建器在 Eclipse 中不起作用

android - 如何获取文件内容的 ParcelFileDescriptor?

android - Listview setEmptyView 无法正常工作

android - 从 Android 中的库项目调用应用程序 Activity

android - 如何在 LinearLayout 中将 GLSurfaceView 与其他 View (例如 TextView 或 Button)一起使用?

android - youtube Android 应用程序是否使用 "DIAL"协议(protocol)?

android - 是否可以禁用 listView 上的滚动?

java - recyclerview 中的 list.remove() 错误

android - 使用 Android Intent.ACTION_SEND 发送电子邮件

java - Android 在启动应用程序时出现运行时错误