久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4176|回復: 1
打印 上一主題 下一主題
收起左側

安卓Java源程序 帶選擇頭像功能的用戶注冊 使用Intent回傳數據

[復制鏈接]
跳轉到指定樓層
樓主
本帖最后由 dori 于 2020-12-18 23:12 編輯

完成帶選擇頭像功能的用戶注冊應用程序開發。
           圖1
           圖2
           圖3

MainActivity.java文件:
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //獲取界面上的組件
        Button bn=findViewById(R.id.bn);
        //為按鈕綁定事件監聽器
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //創建需要對應于目標Activity的Intent
                Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                //啟動指定Activity并等待返回結果,其中0x11是請求碼,用于標識該請求
                startActivityForResult(intent,0x11);
            }
        });
    }
    @Override
    public void onActivityResult(int requestCode,int resultCode,Intent intent)
    {
        //當requestCode、resultCode同時為0x11時,即處理特定的結果
        if(requestCode==0x11&&resultCode==0x11)
        {
            //取出Intent里的Extras數據
            Bundle data=intent.getExtras();
            //取出Bundle中的數據
            int imageId=data.getInt("ID");
            ImageView imageView=findViewById(R.id.iv);
            imageView.setImageResource(imageId);
        }
    }
}
SecondActivity.java文件:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class SecondActivity extends Activity {
    //獲取圖片
    public int []imageId=new int []{R.drawable.img01,R.drawable.img02,R.drawable.img03,
            R.drawable.img04, R.drawable.img05,R.drawable.img06,R.drawable.img07,
            R.drawable.img08,R.drawable.img09};
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        //獲取組件
        GridView gridView=findViewById(R.id.gridView1);
        BaseAdapter adapter=new BaseAdapter() {
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView imageView;
                if(convertView==null)
                {
                    imageView=new ImageView(SecondActivity.this);
                    imageView.setAdjustViewBounds(true);
                    imageView.setMaxWidth(158);
                    imageView.setMaxHeight(150);
                    imageView.setPadding(5, 5, 5, 5);
                }
                else
                {
                    imageView=(ImageView)convertView;
                }
                imageView.setImageResource(imageId[position]);
                return imageView;
            }
            @Override
            public long getItemId(int position) {
                return position;
            }
            @Override
            public Object getItem(int position) {
                return position;
            }
            @Override
            public int getCount() {
                return imageId.length;
            }
        };
        gridView.setAdapter(adapter);
        //綁定監聽器
        gridView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //獲得Intent
                Intent intent=getIntent();
                Bundle bundle=new Bundle();
                bundle.putInt("ID", imageId[position]);
                intent.putExtras(bundle);
                setResult(0x11,intent);
                finish();
            }
        });
    }
}
activity_main.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="247dp"
        android:layout_height="280dp"
        android:layout_marginTop="100dp"
        android:layout_marginEnd="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginBottom="365dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/linearLayout"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="59dp">

            <TextView
                android:id="@+id/textView"
                android:layout_width="143dp"
                android:layout_height="match_parent"
                android:text="用戶名:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/editText"
                android:layout_width="145dp"
                android:layout_height="match_parent"
                android:ems="10"
                android:gravity="start|top"
                android:inputType="textMultiLine" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="59dp">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="143dp"
                android:layout_height="match_parent"
                android:text="密碼:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/editText2"
                android:layout_width="118dp"
                android:layout_height="match_parent"
                android:ems="10"
                android:inputType="number" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="59dp">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="143dp"
                android:layout_height="49dp"
                android:text="確認密碼:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/editText3"
                android:layout_width="120dp"
                android:layout_height="match_parent"
                android:ems="10"
                android:inputType="number" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="59dp">

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="59dp"
                android:text="E-mail地址:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/editText4"
                android:layout_width="103dp"
                android:layout_height="match_parent"
                android:ems="10"
                android:gravity="start|top"
                android:inputType="textMultiLine" />
        </TableRow>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="121dp"
        android:layout_height="283dp"
        android:layout_marginStart="2dp"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="100dp"
        android:layout_marginBottom="363dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/linearLayout2"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/iv"
            android:layout_width="match_parent"
            android:layout_height="170dp"
            app:srcCompat="@drawable/icon" />

        <Button
            android:id="@+id/bn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="選擇頭像"
            android:textSize="20sp" />
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
avtivity_second.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10px"
        android:horizontalSpacing="3px"
        android:verticalSpacing="3px"
        android:numColumns="4"/>
</LinearLayout>
使用Intent回傳數據.rar (9.04 MB, 下載次數: 5)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:1143878 發表于 2025-2-21 08:15 | 只看該作者
我沒學過,問問大神,這個代碼已經包含前端的嗎?
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲精品欧美 | www.久久.com | 中文字幕av网 | 久久网站免费视频 | 欧美无乱码久久久免费午夜一区 | jizz亚洲人 | 中文字幕亚洲精品 | 国内精品视频一区二区三区 | 日韩久久在线 | 国产高清免费在线 | 最新毛片网站 | 中文字幕综合 | 久久久久久久香蕉 | 男女性毛片 | 一级毛片在线播放 | 一级做a爰片久久毛片 | 亚洲精品1区 | 成人小视频在线观看 | 91xx在线观看 | av免费在线播放 | 国产激情一区二区三区 | 中文字幕欧美日韩一区 | 91.色| 精品91| 伊人激情综合网 | 午夜免费在线电影 | 国产十日韩十欧美 | 成人国产在线视频 | 亚洲精品一区二区在线观看 | 欧州一区二区三区 | 成人久久18免费网站图片 | 四虎av电影 | 欧美一级免费观看 | 亚洲va中文字幕 | 久久国产精品久久国产精品 | 日韩一级 | 99久久久久 | 免费观看成人性生生活片 | 亚洲欧美一区二区三区国产精品 | 亚洲黄色成人网 | 99视频精品 |