Android Listview 只显示一项 [英] Android Listview show only one item

查看:19
本文介绍了Android Listview 只显示一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView,我在其中更改了行的外观,但 listview 的大小为一行,而不是全屏.

I have a ListView, where i changed appearence of row, but listview have size of one row, instead of fullscreen.

list_item.xml:

list_item.xml:

<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="wrap_content"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView_news_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#0082A8" />

    <TextView
        android:id="@+id/textView_news_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

tab_news.xml:

tab_news.xml:

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

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

 </ListView>

  </LinearLayout>

制作适配器:

public class RSSAdapter extends ArrayAdapter<RSSitem> {
Context context; 
int layoutResourceId;    
ArrayList<RSSitem> data = null;
SimpleDateFormat sdf = new SimpleDateFormat("kk:mm ");
public RSSAdapter(Context context, int layoutResourceId, ArrayList<RSSitem> data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    NewsHolder holder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new NewsHolder();
        holder.txtTime = (TextView)row.findViewById(R.id.textView_news_time);
        holder.txtNews = (TextView)row.findViewById(R.id.textView_news_header);

        row.setTag(holder);
    }
    else
    {
        holder = (NewsHolder)row.getTag();
    }

    RSSitem item = data.get(position);
    holder.txtTime.setText(sdf.format(item.getPubDate()));
    holder.txtNews.setText(item.getTitle());

    return row;
}

static class NewsHolder
{
    TextView txtTime;
    TextView txtNews;
}

项目正在滚动.

抱歉英语不好.感谢帮助

Sorry for bad English. Thanks for help

@Varun 的建议没有帮助

Advice of @Varun didn't help

我发现错误.谢谢.在答案"中回答)

I found mistake. Thanks. Answer in "answers")

推荐答案

我发现错误.tab_news 在 TabHost 的 ScrollView 中.这么愚蠢的错误(感谢您的帮助.

I Found mistake. tab_news was in ScrollView of TabHost. So stupid mistake( Thanks for help.

更新:ListView 不得在 xml 中的ScrollView.如果是,就会出现同样的问题.

Update:ListView must not be underScrollView in xml. If it is,the same problem occurs.

更新 2 :您可以使用 NestedScrollView

Update 2 :You may use NestedScrollView

这篇关于Android Listview 只显示一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆