zoukankan      html  css  js  c++  java
  • 简易购物商城

    <?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;
         }
     }
    

      

  • 相关阅读:
    Rust交叉编译Mac编译Linux/Windows平台
    SpringBoot 如何生成接口文档
    Echarts + Python 实现的动态实时大屏范例
    计算机中的0.1+0.2=0.3吗?(无可避免的浮点误差)
    Odin线刷失败的常见错误原因分析及解决方法(转载)
    Odin3 刷机工具刷机教程, BL、AP、CP 与 CSC 是什么意思(转载)
    各种常见USB接口类型
    三星S8+手机,刷机经验
    小米8手机,MIUI由12.5降级到9.5、安卓由10降到8;先ROOT,再安装Magisk、Xposed的步骤
    手机刷机相关,若干名词
  • 原文地址:https://www.cnblogs.com/w200100/p/13887615.html
Copyright © 2011-2022 走看看