2013-06-03 81 views
0

我想一个按钮添加到列表视图的页脚中添加脚注按钮,我使用的ListView水平,该适配器类如何在水平列表视图

public ItemAdapter(Context context, int layout, Cursor c,String[] from, int[] to) { 
     super(context, layout, c, from, to,0); 
     this.layout = layout; 
     inflator= LayoutInflater.from(context); 

    } 

我返回NewView的和bindView:

public View newView(Context context, Cursor cursor, ViewGroup parent) {  
     View v = inflator.inflate(layout, parent, false); 
     TextView footer = (TextView)v.findViewById(R.id.bAdd); 
     return v; 

    } 

    @Override 
    public void bindView(View v, final Context context, Cursor c) { 
     final int id = c.getInt(c.getColumnIndex(ItemDb.ID)); 
     final String name = c.getString(c.getColumnIndex(ItemDb.NAME)); 
     } 

和活动类:

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState);  
     String[] from = new String[] { ItemDb.NAME, ItemDb.CONDITION, ItemDb.EMAIL}; 
     int[] to = new int[] { R.id.etItemName, R.id.etItemCondition, R.id.etEmail }; 
     itemAdapter = new ItemAdapter(this,R.layout.list_item, null, from, to); 
     this.setListAdapter(itemAdapter); 
    } 

我怎样才能在listview页脚中添加按钮? 这里是我的xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/photo" 
     android:layout_width="85dp" 
     android:layout_height="85dp" 
     android:background="@drawable/photo_frame" 
     android:contentDescription="@string/imagedescription" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 


    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/condition" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/name" 
      android:layout_marginLeft="10dp" 
      android:text="@string/condition" 
      android:textColor="#000" 
      android:textSize="14sp" /> 

     <TextView 
      android:id="@+id/email" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/condition" 
      android:layout_marginLeft="10dp" 
      android:text="@string/email" 
      android:textColor="#000" 
      android:textSize="14sp" /> 

    </RelativeLayout> 

</LinearLayout> 

回答

0
  1. 适配器列表视图返回data.size()+1元素的覆盖getCount();
  2. 在getView()将是这样的:

    如果(位置== data.size()){ 回报getFooterView();
    }

getFooterView()膨胀与按钮适当的布局。

+0

另外看看这个线程: http://stackoverflow.com/questions/6924047/android-show-listview-between-header-and-footer – QVDev

+0

哈哈,只是想说,不是真的明白你的意思.. 感谢您的额外链接,我尝试先学习。 ^^ – user2301281

+0

但我完全不使用listview,我怎么能应用** listView.addFooterView(页脚); **在我的情况? >。< 我只有一个xml。 http://www.vogella.de/articles/AndroidListView/article.html#headerfooter – user2301281