
<?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="35dp" androID:background="#009688" androID:gravity="center" androID:text="购物清单" androID:textcolor="#E91E63" androID:textSize="25sp" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:orIEntation="vertical"> <ListVIEw androID:ID="@+ID/fruit_item" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /> </linearLayout></linearLayout>
package com.example.shopPingList;import androIDx.appcompat.app.AppCompatActivity;import androID.app.Activity;import androID.os.Bundle;import androID.Widget.ListVIEw;import java.util.ArrayList;import java.util.List;public class MainActivity extends Activity { final List<Fruit> fruitList = new ArrayList<Fruit>(); @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); initFruits(); FruitAdapte adapter = new FruitAdapte(this,R.layout.item,fruitList); ListVIEw lv = (ListVIEw)findVIEwByID(R.ID.fruit_item); lv.setAdapter(adapter); } public voID initFruits(){ Fruit annona squamosa = new Fruit("释迦果","20元1斤",R.mipmap.annona squamosa); fruitList.add(annona squamosa); Fruit apple= new Fruit("苹果","5元1斤",R.mipmap.apple); fruitList.add(apple); Fruit banana = new Fruit("香蕉","9元1斤",R.mipmap.banana); fruitList.add(banana); Fruit strawBerry = new Fruit("草莓","30元1斤",R.mipmap.strawBerry ); fruitList.add(strawBerry ); Fruit orange= new Fruit("橙子","10元1斤",R.mipmap.orange); fruitList.add(orange); Fruit watermelon = new Fruit("西瓜","20元1斤",R.mipmap.watermelon); fruitList.add(watermelon); Fruit hami melon= new Fruit("哈密瓜","15元1斤",R.mipmap.hami melon); fruitList.add(hami melon); }}package com.example.shopPingList;public class Fruit { private int imageID; private String name,Price; public Fruit(String name, String Price, int imageID) { super(); this.imageID = imageID; this.name = name; this.Price = Price; } public int getimageID() { return imageID; } public voID setimageID(int imageID) { this.imageID = imageID; } public String getname() { return name; } public voID setname(String name) { name = name; } public String getPrice() { return Price; } public voID setPrice(String price) { Price = price; } public Object getItem(int position){ return position; }}package com.example.shopPingList;import androID.content.Context;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.ArrayAdapter;import androID.Widget.ImageVIEw;import androID.Widget.TextVIEw;import java.util.List;public class FruitAdapte extends ArrayAdapter { int resourceID; public FruitAdapte(Context context, int resource, List<Fruit> objects){ super(context, resource,objects); resourceID=resource; } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent){ Fruit fruit = (Fruit)getItem(position); VIEw vIEw = LayoutInflater.from(getContext()).inflate(resourceID,null); ImageVIEw iv = (ImageVIEw)vIEw.findVIEwByID(R.ID.imageVIEw); TextVIEw tv = (TextVIEw)vIEw.findVIEwByID(R.ID.textname); TextVIEw pv = (TextVIEw)vIEw.findVIEwByID(R.ID.textPrice); iv.setimageResource(fruit.getimageID()); tv.setText((CharSequence) fruit.getname()); pv.setText((CharSequence)fruit.getPrice()); return vIEw; }}<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <ImageVIEw androID:ID="@+ID/imageVIEw" androID:layout_wIDth="100dp" androID:layout_height="100dp" app:srcCompat="@mipmap/grape" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="100dp" androID:gravity="left|center_vertical" androID:orIEntation="vertical" androID:scrollbarSize="8dp"> <TextVIEw androID:ID="@+ID/textname" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="草莓" /> <TextVIEw androID:ID="@+ID/textPrice" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="价格:30元1斤" androID:textSize="16sp" /> </linearLayout></linearLayout>
总结
以上是内存溢出为你收集整理的购物菜单全部内容,希望文章能够帮你解决购物菜单所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)