2012-10-31 41 views
0

我使用自定义视图(image + frameLayout)创建列表视图,但问题是当我点击列表视图上的任何项目时,getView方法被称为等于ilst视图中的项目数,ListView中的CustomView

我在这里给我的xmi文件。

custon_layout.xml 


<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="5dp"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:src="@drawable/ic_launcher" 
     /> 

    <FrameLayout 
     android:id="@+id/frame" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Landed" 
      android:layout_gravity="center" 
      /> 

     <LinearLayout 
      android:id="@+id/ll1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#ffffff" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/from_user" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="hi" 
       android:textColor="#000000" /> 

      <TextView 
       android:id="@+id/from_user_id" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="hi" 
       android:textColor="#000000" /> 
     </LinearLayout> 
    </FrameLayout> 

    </LinearLayout> 

请帮助我,提前感谢。

+0

我想你想如果你的视图有2个文本和一个图像,那么只有文本有不同的点击事件和图像有不同的点击事件。是吗 ? –

+0

不要使用框架布局,只能使用线性布局来处理此问题。代码检查此:http://stackoverflow.com/a/12813906/1168654 –

+0

您的问题是为什么getView方法被重复调用。我对吗? –

回答

0

你好,我改变了你的xml文件列表请检查这个。

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:padding="5dp"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:src="@drawable/icon" 
     /> 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" 
    android:orientation="vertical"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Landed" 
      android:layout_gravity="center" 
      /> 
      <TextView 
       android:id="@+id/from_user" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="hi" 
       android:textColor="#000000" /> 

      <TextView 
       android:id="@+id/from_user_id" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="hi" 
       android:textColor="#000000" /> 
    </LinearLayout> 

    </LinearLayout> 

现在列表项单击clickhere

可以为所有列表项做同样的点击一下,你可以把不同的看法不同的点击(平均列表项)。

它非常简单,如果你有查询然后下面评论。

+0

@dahval:tahnx但我想滑动,包含两个textView和按钮的线性布局必须低于线性布局,它会在线性布局滑动后可见使用linearlayoyt –

+0

是的,这是可能的,你必须使用VISIBLE进行布局和视图。就像你必须隐藏按钮那样 - > btn.setVisiblity(Button.GONE);如果你要显示按钮,然后btn.setVisiblity(Button.VISIBALE); –

+0

还有一件事现在你问堆栈溢出问题。那么请加上您的所有需求并进行详细说明。那么你有完美的答案,它可能会帮助你。 –