亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

listview在android中使用怎么實現多列模版

發布時間:2020-11-20 16:52:40 來源:億速云 閱讀:515 作者:Leah 欄目:移動開發

listview在android中使用怎么實現多列模版?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

android 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); 
  } 
} 

關于listview在android中使用怎么實現多列模版問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

杭州市| 苏尼特右旗| 潍坊市| 双城市| 瑞金市| 左权县| 清涧县| 绥芬河市| 沙田区| 长葛市| 察哈| 林州市| 奎屯市| 淮南市| 福泉市| 呼图壁县| 凤城市| 洪江市| 山东省| 平塘县| 石首市| 贵定县| 托里县| 县级市| 家居| 区。| 祁阳县| 明光市| 沁水县| 黎平县| 阿城市| 靖州| 澄迈县| 松潘县| 饶平县| 浦北县| 鄂托克旗| 临泽县| 和顺县| 绥棱县| 博乐市|