重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

listview在android中使用怎么实现多列模版

listview在android中使用怎么实现多列模版?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

创新互联建站是一家集网站建设,凭祥企业网站建设,凭祥品牌网站建设,网站定制,凭祥网站建设报价,网络营销,网络优化,凭祥网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

android listview多列模版

 
 
   
   
   
   
   
   
   
   
   
   
   
 

listviewadapter.java:

public class listviewAdapter extends BaseAdapter 
{ 
  public ArrayList> list; 
  Activity activity; 
   
  public listviewAdapter(Activity activity, ArrayList> 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 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> 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 temp = new HashMap(); 
      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 temp1 = new HashMap(); 
      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 temp2 = new HashMap(); 
      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 temp3 = new HashMap(); 
      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 temp4 = new HashMap(); 
      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中使用怎么实现多列模版问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


本文名称:listview在android中使用怎么实现多列模版
本文网址:http://cqcxhl.com/article/jgjejg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP