본문 바로가기
Team Project/노테(Note)

1111 안드로이드 스터디

by somsomdah 2019. 11. 11.

지연 ver.

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

   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Login"
       android:textSize="30sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintHorizontal_bias="0.047"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       app:layout_constraintVertical_bias="0.068" />

   <Button
       android:id="@+id/login"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Login"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

<?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"
   app:layout_behavior="@string/appbar_scrolling_view_behavior"
   tools:context=".mainMenu"
   tools:showIn="@layout/activity_main_menu">

   <TextView
       android:id="@+id/textView"
       android:layout_width="196dp"
       android:layout_height="53dp"
       android:text="Main Menu"
       android:textAlignment="center"
       android:textSize="30sp"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintHorizontal_bias="0.0"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent" />

   <Button
       android:id="@+id/mngcust"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="216dp"
       android:text="Manage Customer"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent" />

   <Button
       android:id="@+id/mngStck"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginBottom="236dp"
       android:text="Manage Stocks"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintHorizontal_bias="0.498"
       app:layout_constraintStart_toStartOf="parent" />

   <Button
       android:id="@+id/mngSales"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Manage Sales"
       app:layout_constraintBottom_toTopOf="@+id/mngStck"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintHorizontal_bias="0.501"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toBottomOf="@+id/mngcust"
       app:layout_constraintVertical_bias="0.469" />

</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.study02;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       Button b = findViewById(R.id.login);

       b.setOnClickListener(new View.OnClickListener(){
           public void onClick(View view){
               Intent intent = new Intent(getApplicationContext(), mainMenu.class);
               startActivity(intent);
           }
       });

       Intent passedIntent = getIntent();
       showToastmsg(passedIntent);
   }

   protected void onNewIntent(Intent intent){
       showToastmsg(intent);
       super.onNewIntent(intent);
   }

   public void showToastmsg(Intent intent){
       if(intent != null){
           int num = intent.getIntExtra("num", 0);
           switch(num){
               case 1:
                   Toast.makeText(this,"Back from Managing Customer", Toast.LENGTH_LONG).show();
                   break;
               case 2:
                   Toast.makeText(this,"Back from Managing Sales",Toast.LENGTH_LONG).show();
                   break;
               case 3:
                   Toast.makeText(this,"Back from Managing Stocks",Toast.LENGTH_LONG).show();
                   break;
               default:
                   break;
           }
       }
   }
}
public class mainMenu extends AppCompatActivity {

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

       Button mngcust = findViewById(R.id.mngcust);  //customer manage btn
       Button mngsale = findViewById(R.id.mngSales);
       Button mngstck = findViewById(R.id.mngStck);

       mngcust.setOnClickListener(new View.OnClickListener(){
           public void onClick(View view){
               gotoLogin(1);
               finish();
           }
       });
       mngsale.setOnClickListener(new View.OnClickListener(){
           public void onClick(View view){
               gotoLogin(2);
               finish();

           }
       });
       mngstck.setOnClickListener(new View.OnClickListener(){
           public void onClick(View view){
               gotoLogin(3);
               finish();

           }
       });
       Toolbar toolbar = findViewById(R.id.toolbar);
       setSupportActionBar(toolbar);

       FloatingActionButton fab = findViewById(R.id.fab);
       fab.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                       .setAction("Action", null).show();
           }
       });
   }

   public void gotoLogin(int num){
       Intent intent = new Intent(getApplicationContext(), MainActivity.class);
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
               Intent.FLAG_ACTIVITY_SINGLE_TOP |
               Intent.FLAG_ACTIVITY_CLEAR_TOP);
       intent.putExtra("num",num);
       startActivity(intent);
   }

 

 

장다솜 ver.

<?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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">


        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="200dp"
                android:layout_height="200dp">


                <EditText
                    android:id="@+id/usernameInput"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="?꾩씠??
                    android:gravity="center"
                    android:background="#ffffff00"
                    android:layout_margin="10dp"
                    />

                <EditText
                    android:id="@+id/passwordInput"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="鍮꾨?踰덊샇"
                    android:gravity="center"
                    android:background="#ffffff00"
                    android:layout_margin="10dp"
                    />

            </LinearLayout>

            <Button
                android:id="@+id/loginButton"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="10dp"
                android:layout_gravity="center"
                android:text="濡쒓렇??
                />


        </LinearLayout>

    </RelativeLayout>

</RelativeLayout>
<?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"
    >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">

        <Button
            android:id="@+id/menu01"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:text="怨좉컼 愿€由?
            />

        <Button
            android:id="@+id/menu02"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:text="留ㅼ텧 愿€由?
            />

        <Button
            android:id="@+id/menu03"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:text="?곹뭹 愿€由?
            />


    </LinearLayout>

</RelativeLayout>
package com.example.doit5;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public static final int REQUEST_CODE_MENU=1001; // ?≫떚鍮꾪떚 ?붿껌肄붾뱶 ?뺤쓽

    EditText usernameInput;
    EditText passwordInput;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); // ?덉씠?꾩썐??遺덈윭??

        // 媛앹껜 遺덈윭?ㅺ린
        Button loginButton=(Button) findViewById(R.id.loginButton);
        usernameInput=(EditText) findViewById(R.id.usernameInput);
        passwordInput=(EditText) findViewById(R.id.passwordInput);

        // ?대깽??由ъ뒪???ㅼ젙
        loginButton.setOnClickListener(new View.OnClickListener(){

            // 踰꾪듉???뚮졇???뚯쓽 ?대깽??
            public void onClick(View v){
                // 濡쒓렇?몄갹?먯꽌 ?낅젰諛쏆? ?꾩씠?? ?⑥뒪?뚮뱶 諛쏆븘??
                String username = usernameInput.getText().toString();
                String password=passwordInput.getText().toString();

                // intent 媛앹껜 ?앹꽦, MenuActivity?먯꽌 ?묐룞???)
                Intent intent=new Intent(getApplicationContext(),MenuActivity.class);

                // intent 媛앹껜???ㅼ쓬怨?媛숈? ?댁슜 ?€??
                intent.putExtra("username",username);
                intent.putExtra("password",password);

                // Intent??request code ?명똿, ?≫떚鍮꾪떚 ?묐룞
                startActivityForResult(intent,REQUEST_CODE_MENU);
            }
        });

    }

    // 濡쒓렇?명솕硫댁쑝濡??뚯븘?ㅻ㈃ ?묐룞, 硫붾돱?붾㈃?먯꽌 requestCode, resultCode,intent 諛쏆븘??
    protected void onActivityResult(int requestCode,int resultCode, Intent intent){
        super.onActivityResult(requestCode,resultCode,intent);

        if(requestCode==REQUEST_CODE_MENU){

            if(intent!=null){

                // intent 媛앹껜???€?λ릺?댁엳???댁슜 遺덈윭?ㅺ린
                String menu=intent.getStringExtra("menu");
                String message=intent.getStringExtra("message");

                // ?ㅼ쓬怨?媛숈? ?댁슜 ?꾩슦湲?
                Toast toast =Toast.makeText(getBaseContext(),
                        "result code : "+resultCode+
                        ",menu : "+menu+
                        ",message : "+message,Toast.LENGTH_LONG);
                toast.show();
            }
        }
    }
}
package com.example.doit5;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MenuActivity extends AppCompatActivity {

    public static final int RESPONSE_CODE_OK=200;

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

        // 湲곗〈 intent 媛앹껜 遺덈윭?ㅺ린
        Intent receivedIntent=getIntent();

        // intent ???덈뜕 ?ㅼ쓬怨?媛숈? ?댁슜 遺덈윭?ㅺ린
        String username=receivedIntent.getStringExtra("username");
        String password=receivedIntent.getStringExtra("password");

        Toast.makeText(this,"username : "+username+", password : "+password,Toast.LENGTH_LONG).show();

        // 踰꾪듉 媛앹껜 ?앹꽦
        Button menu01=(Button)findViewById(R.id.menu01);
        Button menu02=(Button)findViewById(R.id.menu02);
        Button menu03=(Button)findViewById(R.id.menu03);

        // 踰꾪듉 ?대깽??
        menu01.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                // ?명뀗??媛앹껜 ?앹꽦
                Intent resultIntent =new Intent();
                // ?명뀗??媛앹껜???댁슜 ?€??
                resultIntent.putExtra("menu","怨좉컼愿€由?硫붾돱");
                resultIntent.putExtra("message","result message is ok!");
                setResult(Activity.RESULT_OK,resultIntent); // Intent??resultCode ?명똿,
                finish(); // 硫붾돱?묓떚鍮꾪떚 醫낅즺, 濡쒓렇?명솕硫댁쑝濡??뚯븘??

            }

        });

        menu02.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Intent resultIntent =new Intent();
                resultIntent.putExtra("menu","留ㅼ텧愿€由?硫붾돱");
                resultIntent.putExtra("message","result message is ok!");

                setResult(Activity.RESULT_OK,resultIntent);
                finish();

            }

        });

        menu03.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Intent resultIntent =new Intent();
                resultIntent.putExtra("menu","?곹뭹愿€由?硫붾돱");
                resultIntent.putExtra("message","result message is ok!");

                setResult(Activity.RESULT_OK,resultIntent);
                finish();

            }

        });
    }
}

 

'Team Project > 노테(Note)' 카테고리의 다른 글

191125 프로젝트 기획  (0) 2019.11.25
191118 회의  (0) 2019.11.18
191104 스터디 인증 및 다음 과제  (0) 2019.11.05
191028 회의록  (0) 2019.10.28
지금까지 상의 내용 및 나아갈 방향.  (0) 2019.10.07

댓글