<?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" androID:orIEntation="vertical"> <TextVIEw androID:ID="@+ID/textVIEw" androID:layout_wIDth="match_parent" androID:layout_height="40dp" androID:textSize="20sp" androID:gravity="center" androID:textcolor="#FFFFFF" androID:text="购物商城" androID:background="#FFA500"/> <ListVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/lv" /></linearLayout>
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:padding="16dp"> <ImageVIEw androID:ID="@+ID/iv" androID:layout_wIDth="100dp" androID:layout_height="75dp" androID:layout_centerVertical="true" /> <relativeLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginleft="10dp" androID:layout_toRightOf="@ID/iv" androID:layout_centerVertical="true" > <TextVIEw androID:ID="@+ID/Title" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="苹果" androID:textSize="20sp"/> <TextVIEw androID:ID="@+ID/cn_price" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="价格" androID:textcolor="#FFA500" androID:textSize="20sp" androID:layout_below="@ID/Title" androID:layout_margintop="10dp"/> <TextVIEw androID:ID="@+ID/price" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="10元/千克" androID:layout_toRightOf="@ID/cn_price" androID:layout_below="@ID/Title" androID:textSize="20sp" androID:textcolor="#FFA500" androID:layout_margintop="10dp"/> </relativeLayout>
package com.example.malllabel;import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.BaseAdapter;import androID.vIEw.VIEwGroup;import androID.Widget.ImageVIEw;import androID.Widget.ListVIEw;import androID.Widget.TextVIEw;public class MainActivity extends AppCompatActivity { private ListVIEw mListVIEw; private String[] Titles={"香蕉","哈密瓜","猕猴挑","西瓜"}; private String[] prices={"15元/kg","30元/kg","35元/kg","10元/kg"}; private int[] icons={R.drawable.banana,R.drawable.hm,R.drawable.kiwifruit,R.drawable.watermelon}; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.mall); mListVIEw =(ListVIEw)findVIEwByID(R.ID.lv); MyBaseAdapter adapter =new MyBaseAdapter(); mListVIEw.setAdapter(adapter); } class MyBaseAdapter extends BaseAdapter{ @OverrIDe public int getCount(){ return Titles.length; } @OverrIDe public Object getItem(int position){ return Titles[position]; } @OverrIDe public long getItemID(int position){ return position; } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { VIEwHolder holder; if(convertVIEw==null){ convertVIEw= VIEw.inflate(MainActivity.this,R.layout.ListvIEw,null); holder =new VIEwHolder(); holder.Title = convertVIEw.findVIEwByID(R.ID.Title); holder.price = convertVIEw.findVIEwByID(R.ID.price); holder.iv= convertVIEw.findVIEwByID(R.ID.iv); convertVIEw.setTag(holder); }else { holder=(VIEwHolder) convertVIEw.getTag(); } holder.Title.setText(Titles[position]); holder.price.setText(prices[position]); holder.iv.setimageResource(icons[position]); return convertVIEw; } } class VIEwHolder{ TextVIEw Title; TextVIEw price; ImageVIEw iv; } }总结
以上是内存溢出为你收集整理的安卓简易购物商城全部内容,希望文章能够帮你解决安卓简易购物商城所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)