gpt4 book ai didi

android - ListView 一次只显示一行

转载 作者:太空狗 更新时间:2023-10-29 15:17:24 25 4
gpt4 key购买 nike

我遇到了一个 ListView 的问题,它一次只显示一行,即使有很多行。 ListView 包含在选项卡中,因此问题可能出在 ListView 中而不是在 ListView 中。我首先尝试在单独的布局文件中定义 ListView ,并在创建选项卡时使用它。当这不起作用时,我将其放入带有选项卡定义的 FrameLayout 中。相同的结果。

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost">
<LinearLayout android:id="@+id/LinearLayout01"
android:orientation="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_height="fill_parent" android:layout_width="wrap_content"></TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ListView android:id="@+id/list1" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView></FrameLayout>
</LinearLayout>
</TabHost>

这是我用来创建和添加选项卡的代码:

protected void addTab(String tabName, TabHost.TabContentFactory tabFactory){
TabSpec tabSpec = tabHost.newTabSpec(tabName);
tabSpec.setIndicator(tabName);
tabSpec.setContent(tabFactory);
tabHost.addTab(tabSpec);
tabs.add(new TabDetails(tabName,tabFactory));

}

我称之为:

addTab("Medical Center Tests",this);

并包含此代码以创建选项卡内容:

@Override
public View createTabContent(String tag) {


// Get the data returned from the servelet and display it in the ListView
data = getDataArray(this.getIntent().getExtras());




ListView lv = (ListView) contentView.findViewById(R.id.list1);

lv.setAdapter(new MyMedicalCentersTestsScreenAdapter(this,lv,data));
return lv;
}

数据就在那里。只是 ListView 的高度等于一行的高度。

编辑:

我添加了一些调试命令来查看 getView 请求的位置。它只请求第一行,然后在我滚动时一次请求它们。因此,它肯定会将其视为一个小 ListView 并相应地滚动它们。

编辑 2:

决定尝试一个实验。返回 ListView 的简单列表。

    ListView lv = (ListView) contentView.findViewById(R.id.list1);
// create some dummy strings to add to the list
List<String> list1Strings = new ArrayList<String>();
list1Strings.add("Item 1");
list1Strings.add("Item 2");
list1Strings.add("Item 3");
list1Strings.add("Item 4");
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));

还是一样。一次只有一行。

最佳答案

您定义布局的高度而不是使用 fill_parent...

代码:

 layout_height ="150dp"

关于android - ListView 一次只显示一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11492185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com