购物界面

购物界面,第1张

概述<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"android:layout_width="match_parent"android:layout_height="match_parent"
<?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="#fff"        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>
<?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="@drawable/banana" /><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="价格:2元1斤"        androID:textSize="16sp" /></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 orange = new Fruit("橙子","3元1斤",R.drawable.orange );        fruitList.add(orange);        Fruit cherry = new Fruit("苹果","4元1斤",R.drawable.apple);        fruitList.add(cherry);        Fruit grape = new Fruit("香蕉","2元1斤",R.drawable.banana);        fruitList.add(grape);        Fruit durian = new Fruit("火龙果","6元1斤",R.drawable.dragon );        fruitList.add(durian);        Fruit mango = new Fruit("桃子","6元1斤",R.drawable.peach );        fruitList.add(mango);        Fruit litchi = new Fruit("梨","4元1斤",R.drawable.pear);        fruitList.add(litchi);        Fruit guava = new Fruit("西瓜","1.5元1斤",R.drawable.watermelon);        fruitList.add(guava);    }}
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;    }}
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;    }}

总结

以上是内存溢出为你收集整理的购物界面全部内容,希望文章能够帮你解决购物界面所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1057268.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存