亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android listview的多列模版實例代碼

 更新時間:2017年01月24日 11:35:06   投稿:lqh  
這篇文章主要介紹了android listview的多列模版實例代碼的相關(guān)資料,這里附有實例代碼,具有參考價值,需要的朋友可以參考下

android listview多列模版

在listview中,可以做出多列模版的效果,關(guān)鍵還是在listview的模版本,比如如下:

<LinearLayout  
  android:id="@+id/relativeLayout1"  
  android:layout_height="fill_parent"  
  android:layout_width="fill_parent" 
  xmlns:android="http://schemas.android.com/apk/res/android"> 
 
  <TextView 
    android:id="@+id/FirstText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="First" 
    android:layout_weight="1"> 
  </TextView> 
   
  <TextView 
    android:id="@+id/SecondText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="Second" 
    android:layout_weight="2"> 
  </TextView> 
   
  <TextView 
    android:id="@+id/ThirdText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="Third" 
    android:layout_weight="1"> 
  </TextView> 
   
  <TextView 
    android:id="@+id/FourthText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:text="Fourth" 
    android:layout_weight="1"> 
  </TextView> 
</LinearLayout> 

listviewadapter.java:

public class listviewAdapter extends BaseAdapter 
{ 
  public ArrayList<HashMap<String,String>> list; 
  Activity activity; 
   
  public listviewAdapter(Activity activity, ArrayList<HashMap<String,String>> list) { 
    super(); 
    this.activity = activity; 
    this.list = list; 
  } 
 
   
  public int getCount() { 
    // TODO Auto-generated method stub 
    return list.size(); 
  } 
 
   
  public Object getItem(int position) { 
    // TODO Auto-generated method stub 
    return list.get(position); 
  } 
 
 
  public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return 0; 
  } 
 
  private class ViewHolder { 
      TextView txtFirst; 
      TextView txtSecond; 
      TextView txtThird; 
      TextView txtFourth; 
   } 
 
    
 
  public View getView(int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
     
    // TODO Auto-generated method stub 
        ViewHolder holder; 
        LayoutInflater inflater = activity.getLayoutInflater(); 
 
        if (convertView == null) 
        { 
          convertView = inflater.inflate(R.layout.listview_row, null); 
          holder = new ViewHolder(); 
          holder.txtFirst = (TextView) convertView.findViewById(R.id.FirstText); 
          holder.txtSecond = (TextView) convertView.findViewById(R.id.SecondText); 
          holder.txtThird = (TextView) convertView.findViewById(R.id.ThirdText); 
          holder.txtFourth = (TextView) convertView.findViewById(R.id.FourthText); 
          convertView.setTag(holder); 
        } 
        else 
        { 
          holder = (ViewHolder) convertView.getTag(); 
        } 
 
        HashMap<String, String> map = list.get(position); 
        holder.txtFirst.setText(map.get(FIRST_COLUMN)); 
        holder.txtSecond.setText(map.get(SECOND_COLUMN)); 
        holder.txtThird.setText(map.get(THIRD_COLUMN)); 
        holder.txtFourth.setText(map.get(FOURTH_COLUMN)); 
 
      return convertView; 
  } 

主程序: 

public class MultiColumnActivity extends Activity  
{ 
  private ArrayList<HashMap<String,String>> list; 
   
  public void onCreate(Bundle savedInstanceState)  
  { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
 
    ListView lview = (ListView) findViewById(R.id.listview); 
    populateList(); 
    listviewAdapter adapter = new listviewAdapter(this, list); 
    lview.setAdapter(adapter); 
  }   
 
  private void populateList() { 
     
    list = new ArrayList<HashMap<String,String>>(); 
     
    HashMap<String,String> temp = new HashMap<String,String>(); 
      temp.put(FIRST_COLUMN,"Colored Notebooks"); 
      temp.put(SECOND_COLUMN, "By NavNeet"); 
      temp.put(THIRD_COLUMN, "Rs. 200"); 
      temp.put(FOURTH_COLUMN, "Per Unit"); 
    list.add(temp); 
     
    HashMap<String,String> temp1 = new HashMap<String,String>(); 
      temp1.put(FIRST_COLUMN,"Diaries"); 
      temp1.put(SECOND_COLUMN, "By Amee Products"); 
      temp1.put(THIRD_COLUMN, "Rs. 400"); 
      temp1.put(FOURTH_COLUMN, "Per Unit"); 
    list.add(temp1); 
     
    HashMap<String,String> temp2 = new HashMap<String,String>(); 
      temp2.put(FIRST_COLUMN,"Note Books and Stationery"); 
      temp2.put(SECOND_COLUMN, "By National Products"); 
      temp2.put(THIRD_COLUMN, "Rs. 600"); 
      temp2.put(FOURTH_COLUMN, "Per Unit"); 
    list.add(temp2); 
     
    HashMap<String,String> temp3 = new HashMap<String,String>(); 
      temp3.put(FIRST_COLUMN,"Corporate Diaries"); 
      temp3.put(SECOND_COLUMN, "By Devarsh Prakashan"); 
      temp3.put(THIRD_COLUMN, "Rs. 800"); 
      temp3.put(FOURTH_COLUMN, "Per Unit"); 
    list.add(temp3); 
     
    HashMap<String,String> temp4 = new HashMap<String,String>(); 
      temp4.put(FIRST_COLUMN,"Writing Pad"); 
      temp4.put(SECOND_COLUMN, "By TechnoTalaktive Pvt. Ltd."); 
      temp4.put(THIRD_COLUMN, "Rs. 100"); 
      temp4.put(FOURTH_COLUMN, "Per Unit"); 
    list.add(temp4); 
  } 
} 

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • Apache?Cordova?Android原理應(yīng)用實例詳解

    Apache?Cordova?Android原理應(yīng)用實例詳解

    這篇文章主要為大家介紹了Apache?Cordova?Android原理應(yīng)用實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • Android intent之間復(fù)雜參數(shù)傳遞方法詳解

    Android intent之間復(fù)雜參數(shù)傳遞方法詳解

    這篇文章主要介紹了Android intent之間復(fù)雜參數(shù)傳遞方法,較為詳細的分析了Android中intent參數(shù)傳遞的常見方法與使用技巧,需要的朋友可以參考下
    2016-10-10
  • 詳解Android中的沉浸式狀態(tài)欄效果實例

    詳解Android中的沉浸式狀態(tài)欄效果實例

    本篇文章主要介紹了Android中的沉浸式狀態(tài)欄效果,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • Android中RecyclerView實現(xiàn)簡單購物車功能

    Android中RecyclerView實現(xiàn)簡單購物車功能

    這篇文章主要為大家詳細介紹了Android中RecyclerView實現(xiàn)簡單購物車功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Java ArrayList源碼深入分析

    Java ArrayList源碼深入分析

    ArrayList 類是一個可以動態(tài)修改的數(shù)組,與普通數(shù)組的區(qū)別就是它是沒有固定大小的限制,我們可以添加或刪除元素。ArrayList 繼承了 AbstractList,并實現(xiàn)了List接口
    2022-08-08
  • Android 實現(xiàn)微信登錄詳解

    Android 實現(xiàn)微信登錄詳解

    本文主要介紹Android 微信登錄分享朋友圈,這里給大家詳細介紹了Android微信登錄的詳細流程,有需要的小伙伴可以參考下
    2016-07-07
  • Android應(yīng)用中加入微信分享簡單方法

    Android應(yīng)用中加入微信分享簡單方法

    這篇文章主要介紹了Android應(yīng)用中加入微信分享簡單方法,本文用簡潔明快的步驟講解了加入微信分享的方法,需要的朋友可以參考下
    2015-05-05
  • Android編程實現(xiàn)播放音頻的方法示例

    Android編程實現(xiàn)播放音頻的方法示例

    這篇文章主要介紹了Android編程實現(xiàn)播放音頻的方法,結(jié)合實例形式分析了Android使用MediaPlayer類播放音頻的相關(guān)操作技巧,需要的朋友可以參考下
    2017-08-08
  • Android列表組件ListView使用詳解之動態(tài)加載或修改列表數(shù)據(jù)

    Android列表組件ListView使用詳解之動態(tài)加載或修改列表數(shù)據(jù)

    今天小編就為大家分享一篇關(guān)于Android列表組件ListView使用詳解之動態(tài)加載或修改列表數(shù)據(jù),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Android Studio多渠道批量打包及代碼混淆

    Android Studio多渠道批量打包及代碼混淆

    這篇文章主要介紹了Android Studio多渠道批量打包及代碼混淆的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09

最新評論