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

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

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

本文實(shí)例為大家分享了Android實(shí)現(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="價(jià)格:   "
        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控件
    //商品名稱、價(jià)格、圖片集合
    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)建一個(gè)Adapter實(shí)例
        listView.setAdapter(adapter);    //設(shè)置adapter,將適配器指定給ListView對象
    }
    //創(chuàng)建一個(gè)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()方法加載列表?xiàng)l目的布局文件
                convertView=View.inflate(MainActivity.this,R.layout.listview2,null);
            }
            //獲取列表?xiàng)l目上的控件
            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進(jìn)入前后臺狀態(tài)的實(shí)現(xiàn)

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

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

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

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

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

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

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

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

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

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

    Android自制精彩彈幕效果

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

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

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

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

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

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

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

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

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

最新評論