2012-12-31 71 views
0

我正面临一个问题,即我的getView()开始回收,即使第一次在适配器设置在listview中,我有5个项目第一次可见,并且由于我的要求以恒定值设置列表视图高度(尽管我尝试更改为fill_parent但没有效果)我已经搜索并发现与我的问题link相同! 我已经操作装配阅读并才知道,这种问题是因为ListView的高度不应设置为wrap_content我甚至尝试,但仍然没有效果我日志猫ListView奇怪的行为

I/System.out(17411): getview 0 null 
I/System.out(17411): getview 1 [email protected] 
I/System.out(17411): getview 2 [email protected] 
I/System.out(17411): getview 3 [email protected] 
I/System.out(17411): getview 4 [email protected] 
I/System.out(17411): getview 5 [email protected] 
I/System.out(17411): getview 0 [email protected] 
I/System.out(17411): getview 1 null 
I/System.out(17411): getview 2 null 
I/System.out(17411): getview 3 null 
I/System.out(17411): getview 4 null 

当适配器设置为第一次,(我甚至没有把它的滚动,但仍然是回收不知道为什么) 这里是我的布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/newDramaLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@drawable/background" > 

<RelativeLayout 
    android:id="@+id/header" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:visibility="gone" 
    android:background="@drawable/header"> 

    <Button 
     android:id="@+id/refreshBt" 
     android:layout_width="55dp" 
     android:layout_height="50dp" 
     android:onClick="refresh" 
     android:layout_alignParentRight="true" 
     android:background="@drawable/refresh"/> 
    </RelativeLayout> 

    <LinearLayout 
     android:id="@+id/info" 
     android:layout_width="match_parent" 
     android:layout_height="30dp" 
     android:visibility="gone" 
     android:gravity="center_horizontal" 
     android:layout_below="@+id/header" 
     android:background="@drawable/information" 
     android:paddingLeft="10dp" > 

     <TextView 
      android:id="@+id/label" 
      android:layout_width="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_height="wrap_content" 
      android:text="@string/label" 
      android:textColor="@android:color/secondary_text_dark" /> 
    </LinearLayout> 

<ListView 
    android:id="@+id/newDramasList" 
    android:layout_below="@+id/info" 
    android:cacheColorHint="#00000000" 
    android:layout_width="match_parent" 
    android:layout_centerInParent="true" 
    android:dividerHeight="5dp" 
    android:divider="@android:color/transparent" 
    android:layout_height="320dp" 
    android:visibility="gone"> 

</ListView> 

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:visibility="gone" 
    android:layout_centerInParent="true" /> 

    <LinearLayout 
    android:id="@+id/footer" 
    android:layout_below="@+id/newDramasList" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:visibility="gone" 
    android:background="@drawable/footer"/> 

    </RelativeLayout> 

列表视图我有尝试使其高度FILL_PARENT,但问题仍然没有固定。 这里是我的代码

[email protected] 
public View getView(final int position, View convertView, ViewGroup parent) 
{ 
    System.out.println("getview "+position+" "+convertView); 
    View row=convertView; 

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

     holder=new NewDramas(); 
     holder.ivIcon=(ImageView)row.findViewById(R.id.dramaIcon); 
     holder.tvDramaName=(TextView)row.findViewById(R.id.dramaTitle); 
     holder.tvDate=(TextView)row.findViewById(R.id.date); 

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

    holder.ivIcon.setImageResource(R.drawable.new_drama_icon); 
    holder.tvDramaName.setText(dramaList.get(position).getDramaName()); 
    holder.tvDate.setText(dramaList.get(position).getDate()); 

    return row; 
} 

这里是充气布局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="280dp" 
    android:layout_height="70dp" 
    android:orientation="vertical" 
    android:background="@drawable/new_dramas_list_back" > 

    <ImageView 
     android:id="@+id/dramaIcon" 
     android:layout_width="50dp" 
     android:layout_height="45dp" 
     android:src="@drawable/favorite_icon"/> 
     <Button 
     android:id="@+id/fav" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/dramaIcon" 
     android:visibility="gone" 
     android:focusable="false" 
     android:layout_alignRight="@+id/dramaIcon" 
     android:background="@drawable/heart" 
     /> 

    <TextView 
     android:id="@+id/dramaTitle" 
     android:layout_toRightOf="@+id/dramaIcon" 
     android:layout_alignTop="@+id/dramaIcon" 
     android:layout_width="wrap_content" 
     android:width="150dp" 
     android:paddingTop="5dp" 
     android:textColor="@android:color/white" 
     android:ellipsize="end" 
     android:layout_marginLeft="32dp" 
     android:layout_height="wrap_content" 
     android:text="title" 
     android:textStyle="bold" /> 
    <LinearLayout 
     android:id="@+id/updateDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@+id/dramaIcon" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="2dp" > 
    <TextView 
     android:id="@+id/updated" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="updated:" 
     android:textColor="#ffff00" 
     android:layout_alignBottom="@+id/dramaIcon"/> 

    <TextView 
     android:id="@+id/date" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#ffff00" 
     android:layout_marginLeft="1dp" 
     android:text="12/08/2102" /> 
</LinearLayout>  

</RelativeLayout> 

我还添加了一个按钮,在列表视图我一个footerView?我希望这不是奇怪的行为和一些奇怪的事情的原因,我已经注意到,在logcat中,getview 1的相对ID是5次重复的,这意味着在列表视图中位置1有问题

任何人都可以帮助我理解这种奇怪的行为,在此先感谢。

+0

我不是Android UI的专家,但是我从logcat List看到的是重复使用相同的View for 5 first row。所以List认为每一行都不可见 –

+0

你应该与我们分享膨胀的布局让我们说点什么。 – Talha

+0

@talhakosen我已经添加了膨胀的布局,你现在可以检查它 –

回答

0

android:layout_weight =“1” 尝试将其设置为ListView并且您希望显示它。 (对不起英文:P)

+0

谢谢你的帮助:)但请这应该只是评论 – swiftBoy

+0

@Maury如果有相对布局作为父母,你不能设置一个孩子的重量 –