欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)購物商城

 更新時間:2021年04月22日 15:58:35   作者:星⁠辭歸也  
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)購物商城,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)購物商城的具體代碼,供大家參考,具體內(nèi)容如下

activity_main.xml

<ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:listSelector="#B5DCFA">


</ListView>

listview2.xml

<?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">
    <ImageView
        android:id="@+id/iv"
        android:layout_width="120dp"
        android:layout_height="90dp"
        android:background="@drawable/table"
        android:layout_marginRight="10dp">
    </ImageView>
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/iv"
        android:text="桌子"
        android:textSize="20dp"
        android:layout_marginTop="10dp">
    </TextView>
    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/iv"
        android:layout_below="@id/title"
        android:text="價格:   "
        android:textSize="15dp"
        android:textColor="#FF8F03"
        android:layout_marginTop="15dp">
    </TextView>
    <TextView
        android:id="@+id/count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/price"
        android:layout_toRightOf="@id/price"
        android:textSize="15dp"
        android:text="1000"
        android:textColor="#FF8F03">
    </TextView>
</RelativeLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {
    private ListView listView; //ListView控件
    //商品名稱、價格、圖片集合
    private String[] titles={"桌子","蘋果","蛋糕","線衣","獼猴桃","圍巾"};
    private String[] prices={"1800元","10元/kg","300元","350元","10元/kg","280元"};
    private int[] icons={R.drawable.table,R.drawable.apple,R.drawable.cake,R.drawable.wireclothes,R.drawable.kiwifruit,R.drawable.scarf};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView=findViewById(R.id.lv);       //獲取ListView控件
        MallAdapter adapter=new MallAdapter();    //創(chuàng)建一個Adapter實例
        listView.setAdapter(adapter);    //設(shè)置adapter,將適配器指定給ListView對象
    }
    //創(chuàng)建一個MallAdapter類繼承自BaseAdapter類,并重寫類中的一些方法
    public class MallAdapter extends BaseAdapter {

        @Override
        public int getCount() {   //獲取item條數(shù)
            return titles.length;    //返回ListView Item條目的總數(shù)
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
                /*
        position:當(dāng)前的item的位置
        convertView:指定的單元格布局
        parent:用于加載xml布局
         */
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView==null){
                //通過inflate()方法加載列表條目的布局文件
                convertView=View.inflate(MainActivity.this,R.layout.listview2,null);
            }
            //獲取列表條目上的控件
            TextView title=convertView.findViewById(R.id.title);
            TextView price=convertView.findViewById(R.id.count);
            ImageView iv=convertView.findViewById(R.id.iv);
            //設(shè)置界面上的文本圖片和數(shù)據(jù)信息
            title.setText(titles[position]);
            price.setText(prices[position]);
            iv.setBackgroundResource(icons[position]);
            return convertView;
        }
    }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • flutter監(jiān)聽app進入前后臺狀態(tài)的實現(xiàn)

    flutter監(jiān)聽app進入前后臺狀態(tài)的實現(xiàn)

    在開發(fā)app的過程中,我們經(jīng)常需要知道app處于前后臺的狀態(tài),本文主要介紹了flutter監(jiān)聽app進入前后臺狀態(tài)的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • Android設(shè)計模式之代理模式Proxy淺顯易懂的詳細(xì)說明

    Android設(shè)計模式之代理模式Proxy淺顯易懂的詳細(xì)說明

    Android設(shè)計模式之代理模式也是平時比較常用的設(shè)計模式之一,代理模式其實就是提供了一個新的對象,實現(xiàn)了對真實對象的操作,或成為真實對象的替身
    2018-03-03
  • Android自定義View實現(xiàn)跟隨手指移動的小兔子

    Android自定義View實現(xiàn)跟隨手指移動的小兔子

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實現(xiàn)跟隨手指移動的小兔子,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • Android基于OpenCV實現(xiàn)霍夫直線檢測

    Android基于OpenCV實現(xiàn)霍夫直線檢測

    霍夫變換利用點與線之間的對偶性,將圖像空間中直線上離散的像素點通過參數(shù)方程映射為霍夫空間中的曲線,并將霍夫空間中多條曲線的交點作為直線方程的參數(shù)映射為圖像空間中的直線。給定直線的參數(shù)方程,可以利用霍夫變換來檢測圖像中的直線。本文簡單講解Android的實現(xiàn)
    2021-06-06
  • Android開發(fā)使用HttpURLConnection進行網(wǎng)絡(luò)編程詳解【附源碼下載】

    Android開發(fā)使用HttpURLConnection進行網(wǎng)絡(luò)編程詳解【附源碼下載】

    這篇文章主要介紹了Android開發(fā)使用HttpURLConnection進行網(wǎng)絡(luò)編程的方法,結(jié)合實例形式分析了Android基于HttpURLConnection實現(xiàn)顯示圖片與文本功能,涉及Android布局、文本解析、數(shù)據(jù)傳輸、權(quán)限控制等相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • Android自制精彩彈幕效果

    Android自制精彩彈幕效果

    這篇文章主要為大家詳細(xì)介紹了Android自制精彩彈幕效果,彈幕垂直方向可固定隨機,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android開發(fā)之彈出軟鍵盤工具類簡單示例

    Android開發(fā)之彈出軟鍵盤工具類簡單示例

    這篇文章主要介紹了Android開發(fā)之彈出軟鍵盤工具類,結(jié)合實例形式分析了Android彈出軟鍵盤及獲取焦點的簡單操作技巧,需要的朋友可以參考下
    2018-01-01
  • Android開發(fā)基礎(chǔ)實現(xiàn)最簡單的視頻播放示例

    Android開發(fā)基礎(chǔ)實現(xiàn)最簡單的視頻播放示例

    這篇文章主要為大家介紹了Android開發(fā)基礎(chǔ)實現(xiàn)最簡單的視頻播放示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-02-02
  • 強制Android應(yīng)用使用某個Locale的方法

    強制Android應(yīng)用使用某個Locale的方法

    這篇文章主要介紹了強制Android應(yīng)用使用某個Locale的方法,涉及Android基于Locale進行語言設(shè)置的相關(guān)技巧,需要的朋友可以參考下
    2015-10-10
  • 詳解Andorid開發(fā)中反射機制是怎么一回事

    詳解Andorid開發(fā)中反射機制是怎么一回事

    反射機制是在運行狀態(tài)中,對于任何一個類,都可以知道這個類的所有屬性和方法,對于任何一個對象,都可以調(diào)用它所有的方法和屬性,修改部分類型信息,這種動態(tài)獲取信息以及動態(tài)調(diào)用對象方法的功能稱為Java的反射機制
    2022-11-11

最新評論