zoukankan      html  css  js  c++  java
  • 安卓作业4

    package com.example.aa;
    
    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("橙子","8.5元1斤",R.mipmap.orange);
            fruitList.add(orange);
            Fruit cherry = new Fruit("樱桃","40元1斤",R.mipmap.cherry);
            fruitList.add(cherry);
            Fruit grape = new Fruit("葡萄","5元1斤",R.mipmap.grape);
            fruitList.add(grape);
            Fruit durian = new Fruit("榴莲","50元1斤",R.mipmap.durian);
            fruitList.add(durian);
            Fruit mango = new Fruit("芒果","7元1斤",R.mipmap.mango);
            fruitList.add(mango);
            Fruit litchi = new Fruit("荔枝","15元1斤",R.mipmap.litchi);
            fruitList.add(litchi);
            Fruit guava = new Fruit("石榴","3元1斤",R.mipmap.guava);
            fruitList.add(guava);
    
        }
    }
    <?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.aa;
    
    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;
        }
    
    }
  • 相关阅读:
    中文词频统计及词云制作 25
    实验一 DOS实验 25
    字符串练习 25
    Python、循环的练习 25
    用requests库和BeautifulSoup4库爬取新闻列表 25
    爬取新闻列表 25
    Mockito使用总结
    20121116
    20121123
    20121115
  • 原文地址:https://www.cnblogs.com/hzpiou/p/13897044.html
Copyright © 2011-2022 走看看