Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> Android一個ListView列表之中插入兩種不同的數據,androidlistview

Android一個ListView列表之中插入兩種不同的數據,androidlistview

編輯:關於android開發

Android一個ListView列表之中插入兩種不同的數據,androidlistview


http://www.cnblogs.com/roucheng/ Android一個ListView列表之中插入兩種不同的數據 代碼如下:
public class ViewHolder{
        Button fenzu_btn_1;
        Button fenzu_btn_2;
        Button fenzu_btn_3;
        
    }

    public class ViewHolder1{
        
        TextView tvTitle;
        TextView tvLetter;
        
    }


/**
     * 當ListView數據發生變化時,調用此方法來更新ListView
     * @param list
http://www.cnblogs.com/roucheng/p/csslogin.html
     */


    public void updateListView(List<SortModel> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public int getCount() {
        return this.list.size();
    }

    public Object getItem(int position) {
        return list.get(position);
    }
    
    
@Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub
        int p = position;
        if (p == 0)
            return 0;
        else
            return 1;
    }
    
    @Override
    public int getViewTypeCount() {
        return 2;
    }



public View getView(final int position, View view, ViewGroup arg2) {


int type = getItemViewType(position);
if (view == null) {
            
inflater = LayoutInflater.from(mContext);
if(type==1){
                
        view = inflater.inflate(R.layout.item,arg2, false);
                viewHolder1 = new ViewHolder1();
                viewHolder1.tvTitle= (TextView) view.findViewById(R.id.title);
                viewHolder1.tvLetter= (TextView) view.findViewById(R.id.catalog);
                view.setTag(viewHolder1);
    
            }else{
//http://www.cnblogs.com/roucheng/p/csslogin.html
                view = inflater.inflate(R.layout.items2,arg2, false);
                fenzu_btn_1=(LinearLayout)view.findViewById(R.id.fenzu_btn_1);
                view.setTag(viewHolder);

                          }


       } else {
            
            switch (type) {
            case 1:
                viewHolder1 = (ViewHolder1) view.getTag();
                break;
            case 0:
                viewHolder = (ViewHolder) view.getTag();
                break;
               }
            
        }

return view;

}

 更多特效:http://www.cnblogs.com/roucheng/p/texiao.html

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved