Android--Activity会传数据(装备选择)

本文介绍了如何在Android应用中使用Activity进行数据传递,重点在于startActivityForResult方法的运用。通过创建主界面、装备选择界面,并结合ProgressBar组件展示耗时操作的进度,提升用户体验。详细步骤包括创建各种组件、自定义Info类以及实现ShoppingActivity和MainActivity的交互,最终实现了从装备选择界面返回数据到主界面的效果。
摘要由CSDN通过智能技术生成

1. 训练目标

1.掌握组件ProgressBar的使用

2.掌握startActivityForResult方法的使用

操作步骤:

1.创建程序(主界面):

<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="cn.edu.bu.a13labequipment.MainActivity">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/baby"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="45dp"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="主人,快给小宝宝购买装备吧!"
        android:gravity="center_horizontal"
        android:textSize="18sp"
 
        />
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginTop="25dp">
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
            <TextView
 
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="生命值:"
                />
            <ProgressBar
                android:id="@+id/progressBar1"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:layout_marginLeft="20dp"
                />
            <TextView
                android:id="@+id/tv_life"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="80"
                android:layout_marginTop="5dp"
                android:layout_weight="1"
                android:layout_marginLeft="20dp"
                />
        </TableRow>
        <TableRow
            android:layout_marginTop="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
            <TextView
 
                android:layout_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值