Android?Studio實(shí)現(xiàn)購(gòu)買售賣系統(tǒng)
本文實(shí)例為大家分享了Android Studio實(shí)現(xiàn)購(gòu)買售賣系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
本項(xiàng)目基于安卓系統(tǒng)開發(fā)的界面設(shè)計(jì),包括登錄,主頁(yè)面,展示頁(yè)面,購(gòu)買頁(yè)面等六個(gè)頁(yè)面
ShopActivity
package com.example.tryfirst; ? import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; ? public class ShopActivity extends AppCompatActivity implements View.OnClickListener{ ? ? ? private ItemInfo itemInfo0; ? ? private ItemInfo itemInfo1; ? ? private ItemInfo itemInfo2; ? ? private ItemInfo itemInfo3; ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.activity_shop); ? ? ? ? itemInfo0 = new ItemInfo("空軍一號(hào)"); ? ? ? ? itemInfo1 = new ItemInfo("李寧足球鞋"); ? ? ? ? itemInfo2 = new ItemInfo("匹克太極籃球鞋"); ? ? ? ? itemInfo3 = new ItemInfo("林丹羽毛球鞋"); ? ? ? ? findViewById(R.id.btn_0).setOnClickListener(this); ? ? ? ? findViewById(R.id.btn_1).setOnClickListener(this); ? ? ? ? findViewById(R.id.btn_2).setOnClickListener(this); ? ? ? ? findViewById(R.id.btn_3).setOnClickListener(this); ? ? } ? ? public void onClick(View v){ ? ? ? ? Intent intent; ? ? ? ? switch (v.getId()) { ? ? ? ? ? ? case R.id.btn_0: ? ? ? ? ? ? ? ? intent = new Intent(); ? ? ? ? ? ? ? ? intent.putExtra("shoe",itemInfo0); ? ? ? ? ? ? ? ? setResult(1,intent); ? ? ? ? ? ? ? ? finish(); ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? case R.id.btn_1: ? ? ? ? ? ? ? ? intent = new Intent(); ? ? ? ? ? ? ? ? intent.putExtra("shoe",itemInfo1); ? ? ? ? ? ? ? ? setResult(1,intent); ? ? ? ? ? ? ? ? finish(); ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? case R.id.btn_2: ? ? ? ? ? ? ? ? intent = new Intent(); ? ? ? ? ? ? ? ? intent.putExtra("shoe",itemInfo0); ? ? ? ? ? ? ? ? setResult(1,intent); ? ? ? ? ? ? ? ? finish(); ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? case R.id.btn_3: ? ? ? ? ? ? ? ? intent = new Intent(); ? ? ? ? ? ? ? ? intent.putExtra("shoe",itemInfo0); ? ? ? ? ? ? ? ? setResult(1,intent); ? ? ? ? ? ? ? ? finish(); ? ? ? ? ? ? ? ? break; ? ? ? ? } ? ? } }
ShowActivity
package com.example.tryfirst; ? import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; ? public class ShowActivity extends AppCompatActivity { ? ? ? private TextView tv_name; ? ? private TextView tv_password; ? ? private TextView shoe; ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.activity_show); ? ? ? ? Intent intent = getIntent(); ? ? ? ? String name = intent.getStringExtra("name"); ? ? ? ? String password = intent.getStringExtra("password"); ? ? ? ? tv_name = (TextView) findViewById(R.id.tv_name); ? ? ? ? tv_password = (TextView) findViewById(R.id.tv_password); ? ? ? ? tv_name.setText("用戶名為: " + name); ? ? ? ? tv_password.setText("密碼為: " + password); ? ? ? ? shoe = (TextView) findViewById(R.id.tv_food_progress); ? ? } ? ? public void click0(View view){ ? ? ? ? Intent intent = new Intent(this, FriendActivity.class); ? ? ? ? startActivity(intent); ? ? } ? ? public void click1(View view){ ? ? ? ? Intent intent = new Intent(this,ShopActivity.class); ? ? ? ? startActivityForResult(intent,1); ? ? } ? ? public void click2(View view){ ? ? ? ? Intent intent = new Intent(this,ListActivity.class); ? ? ? ? startActivity(intent); ? ? } ? ? @Override ? ? protected void onActivityResult(int requestCode, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int resultCode,Intent data){ ? ? ? ? super.onActivityResult(requestCode,resultCode,data); ? ? ? ? if(data !=null){ ? ? ? ? ? ? if(requestCode==1){ ? ? ? ? ? ? ? ? if(resultCode==1){ ? ? ? ? ? ? ? ? ? ? ItemInfo info = ? ? ? ? ? ? ? ? ? ? ? ? ? ? (ItemInfo) data.getSerializableExtra("food"); ? ? ? ? ? ? ? ? ? ? updateProgress(info); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? } ? ? private void updateProgress(ItemInfo info){shoe.setText(info.getName()); ? ? } }
ListActivity
package com.example.tryfirst; ? import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class ListActivity extends AppCompatActivity { ? ? private ListView mListView; ? ? private String[] names = {"郭艾倫aj34"}; ? ? private int[] herd = {R.drawable.l}; ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.activity_list); ? ? ? ? mListView = (ListView) findViewById(R.id.lv); ? ? ? ? MyBaseAdapter myAdapter = new MyBaseAdapter(); ? ? ? ? mListView.setAdapter(myAdapter); ? ? } ? ? class MyBaseAdapter extends BaseAdapter { ? ? ? ? @Override ? ? ? ? public int getCount() { ? ? ? ? ? ? return names.length; ? ? ? ? } ? ? ? ? ? @Override ? ? ? ? public Object getItem(int position) { ? ? ? ? ? ? return names[position]; ? ? ? ? } ? ? ? ? ? @Override ? ? ? ? public long getItemId(int position) { ? ? ? ? ? ? return position; ? ? ? ? } ? ? ? ? ? @Override ? ? ? ? public View getView(int position, View convertView, ViewGroup parent) { ? ? ? ? ? ? //將list.xml文件找出來(lái)轉(zhuǎn)化為View對(duì)象 ? ? ? ? ? ? View view = View.inflate(ListActivity.this,R.layout.list,null); ? ? ? ? ? ? TextView mTextView = (TextView) view.findViewById(R.id.tv); ? ? ? ? ? ? mTextView.setText(names[position]); ? ? ? ? ? ? ImageView imageView = (ImageView) view.findViewById(R.id.imge); ? ? ? ? ? ? imageView.setBackgroundResource(herd[position]); ? ? ? ? ? ? return view; ? ? ? ? } ? ? } }
Activity_Shop .xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout ? ? xmlns:android="http://schemas.android.com/apk/res/android" ? ? xmlns:tools="http://schemas.android.com/tools" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:background="@drawable/back" ? ? android:orientation="vertical" ? ? tools:context=".ShopActivity"> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:background="#307f7f7f" ? ? ? ? android:gravity="center_vertical" ? ? ? ? android:orientation="horizontal" ? ? ? ? android:padding="5dp"> ? ? ? ? <ImageView ? ? ? ? ? ? android:layout_width="80dp" ? ? ? ? ? ? android:layout_height="200dp" ? ? ? ? ? ? android:background="@drawable/lin" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="空軍一號(hào)" ? ? ? ? ? ? android:layout_weight="3" ? ? ? ? ? ? android:textSize="35sp" /> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_8" ? ? ? ? ? ? android:text="加入購(gòu)物車" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:id="@+id/btn_0" ? ? ? ? ? ? android:text="購(gòu)買"/> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"> ? ? ? ? <ImageView ? ? ? ? ? ? android:layout_width="80dp" ? ? ? ? ? ? android:layout_height="200dp" ? ? ? ? ? ? android:background="@drawable/longtuos" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="李寧足球鞋" ? ? ? ? ? ? android:textSize="35sp" ? ? ? ? ? ? android:layout_weight="3"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_9" ? ? ? ? ? ? android:text="加入購(gòu)物車" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_1" ? ? ? ? ? ? android:text="購(gòu)買" ? ? ? ? ? ? android:layout_weight="1"/> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"> ? ? ? ? <ImageView ? ? ? ? ? ? android:layout_width="80dp" ? ? ? ? ? ? android:layout_height="200dp" ? ? ? ? ? ? android:background="@drawable/longtuos" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="匹克太極籃球鞋" ? ? ? ? ? ? android:textSize="35sp" ? ? ? ? ? ? android:layout_weight="3"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_6" ? ? ? ? ? ? android:text="加入購(gòu)物車" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_2" ? ? ? ? ? ? android:text="購(gòu)買" ? ? ? ? ? ? android:layout_weight="1"/> ? ? </LinearLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content"> ? ? ? ? <ImageView ? ? ? ? ? ? android:layout_width="80dp" ? ? ? ? ? ? android:layout_height="200dp" ? ? ? ? ? ? android:background="@drawable/longtuos" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <TextView ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? ? ? android:text="林丹羽毛球鞋" ? ? ? ? ? ? android:textSize="35sp" ? ? ? ? ? ? android:layout_weight="3"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_3" ? ? ? ? ? ? android:text="加入購(gòu)物車" ? ? ? ? ? ? android:layout_weight="1"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:id="@+id/btn_4" ? ? ? ? ? ? android:text="購(gòu)買" ? ? ? ? ? ? android:layout_weight="1"/> ? ? </LinearLayout> </LinearLayout>
Activity_Show .xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout ? ? xmlns:android="http://schemas.android.com/apk/res/android" ? ? xmlns:tools="http://schemas.android.com/tools" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:background="@drawable/back" ? ? android:orientation="vertical" ? ? tools:context=".MainActivity"> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:layout_marginTop="70dp" ? ? ? ? android:layout_marginBottom="50dp" ? ? ? ? android:orientation="horizontal" ? ? ? ? android:padding="20dp"> ? ? ? ? <ImageView ? ? ? ? ? ? android:id="@+id/pet" ? ? ? ? ? ? android:layout_width="100dp" ? ? ? ? ? ? android:layout_height="100dp" ? ? ? ? ? ? android:background="@drawable/head"/> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="0dp" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? android:layout_gravity="center" ? ? ? ? ? ? android:orientation="vertical" ? ? ? ? ? ? android:paddingLeft="40dp"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:id="@+id/tv_name" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text=" " ? ? ? ? ? ? ? ? android:textSize="20sp" ? ? ? ? ? ? ? ? android:textColor="#33cc00"/> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:id="@+id/tv_password" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:layout_marginTop="20dp" ? ? ? ? ? ? ? ? android:text=" " ? ? ? ? ? ? ? ? android:textSize="20sp" ? ? ? ? ? ? ? ? android:textColor="#33cc00"/> ? ? ? ? </LinearLayout> ? ? </LinearLayout> ? ? <TableLayout ? ? ? ? android:layout_width="fill_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:layout_gravity="center" ? ? ? ? android:layout_marginBottom="50dp" ? ? ? ? android:layout_marginLeft="20dp" ? ? ? ? android:layout_marginRight="5dp"> ? ? ? ? <TableRow ? ? ? ? ? ? android:layout_width="fill_parent" ? ? ? ? ? ? android:layout_height="wrap_content"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:layout_width="0dip" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:layout_weight="9" ? ? ? ? ? ? ? ? android:text="背景是北宋郭忠恕的明皇避暑宮圖" ? ? ? ? ? ? ? ? android:textColor="#ff0000" ? ? ? ? ? ? ? ? android:textSize="25sp" /> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:id="@+id/tv_food_progress" ? ? ? ? ? ? ? ? android:layout_width="0dip" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:layout_weight="1" ? ? ? ? ? ? ? ? android:layout_gravity="center" ? ? ? ? ? ? ? ? android:text=" " ? ? ? ? ? ? ? ? android:textColor="#99ff77" ? ? ? ? ? ? ? ? android:textSize="40sp"/> ? ? ? ? </TableRow> ? ? </TableLayout> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:orientation="vertical"> ? ? ? ? <Button ? ? ? ? ? ? android:layout_gravity="center" ? ? ? ? ? ? android:layout_marginLeft="28dp" ? ? ? ? ? ? android:layout_marginRight="50dp" ? ? ? ? ? ? android:layout_width="100dp" ? ? ? ? ? ? android:layout_height="100dp" ? ? ? ? ? ? android:background="@drawable/a" ? ? ? ? ? ? android:onClick="click0"/> ? ? ? ? <Button ? ? ? ? ? ? android:layout_gravity="center" ? ? ? ? ? ? android:layout_marginRight="28dp" ? ? ? ? ? ? android:layout_width="100dp" ? ? ? ? ? ? android:layout_height="100dp" ? ? ? ? ? ? android:background="@drawable/buy" ? ? ? ? ? ? android:layout_marginTop="90px" ? ? ? ? ? ? android:onClick="click1"/> ? ? </LinearLayout> ? ? <Button ? ? ? ? android:layout_width="900px" ? ? ? ? android:layout_height="100px" ? ? ? ? android:layout_marginTop="50dp" ? ? ? ? android:text="鞋的列表展示" ? ? ? ? android:onClick="click2" ? ? ? ? android:textColor="#ff0000" ? ? ? ? android:background="#99ff00"/> </LinearLayout>
運(yùn)行結(jié)果展示圖
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā) -- UI界面之threme和style
做Java的人一般都做過(guò)CSS,我們都知道它也有一個(gè)樣式,Android中的樣式也可以進(jìn)行類比。2016-06-06Fedora14下android開發(fā): eclipse與ibus確有沖突的問(wèn)題分析
本篇文章是對(duì)Fedora14下android開發(fā),eclipse與ibus確有沖突的問(wèn)題進(jìn)行了分析介紹,需要的朋友參考下2013-05-05Android Navigation TabBar控件實(shí)現(xiàn)多彩標(biāo)簽欄
這篇文章主要為大家詳細(xì)介紹了Android Navigation TabBar控件實(shí)現(xiàn)多彩標(biāo)簽欄的相關(guān)代碼,感興趣的小伙伴們可以參考一下2016-05-05一文帶你看懂Android Application啟動(dòng)流程是怎樣的
談到Android Application的啟動(dòng)流程,很多文章都是各種源碼類和方法的一堆調(diào)用關(guān)系,這樣的文章就算看一百遍,也只是云里霧里。源碼得看,但是最好不要一下子深陷到源碼的細(xì)節(jié)之中,不可自拔。這里站在前人的基礎(chǔ)之上做一個(gè)總結(jié)2021-10-10SwipeRefreshLayout+RecyclerView實(shí)現(xiàn)上拉刷新和下拉刷新功能
這篇文章主要介紹了SwipeRefreshLayout+RecyclerView實(shí)現(xiàn)上拉刷新和下拉刷新功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01Android自定義ProgressBar實(shí)現(xiàn)漂亮的進(jìn)度提示框
這篇文章主要為大家詳細(xì)介紹了Android自定義ProgressBar實(shí)現(xiàn)漂亮的進(jìn)度提示框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06Android AIDL實(shí)現(xiàn)與服務(wù)相互調(diào)用方式
這篇文章主要介紹了Android AIDL實(shí)現(xiàn)與服務(wù)相互調(diào)用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Android中不支持動(dòng)態(tài)申請(qǐng)權(quán)限的原因
這篇文章主要介紹了Android中不支持動(dòng)態(tài)申請(qǐng)權(quán)限的原因,本文列舉了幾個(gè)不支持動(dòng)態(tài)申請(qǐng)權(quán)限的原因,需要的朋友可以參考下2015-01-01