activity_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"

android:orientation="vertical"
>

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

<TextView
android:id="@+id/textViewID"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="ID"
android:textSize="28dp" />

<EditText
android:id="@+id/eid"
android:layout_width="213dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:hint="ID" />

</LinearLayout>

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

<TextView
android:id="@+id/textViewpw"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_weight="1"
android:text="PW"
android:textSize="26dp" />

<EditText
android:id="@+id/epw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:ems="10"
android:hint="password"
android:inputType="textPassword" />

</LinearLayout>

<Button
android:id="@+id/gotomenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:onClick="login"
android:text="로그인" />

</LinearLayout>


activtiy_main2.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">


<Button
android:id="@+id/customerM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="고객관리"
/>

<Button
android:id="@+id/profitM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="매출관리"
/>
<Button
android:id="@+id/goodsM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="상품관리"
/>

</LinearLayout>

MainActivity.java



import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
public static final int REQUEST_CODE_MENU=101;
String userid="identity";
String userpw="password";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_MENU) {
if (resultCode == RESULT_OK) {
String menu = data.getExtras().getString("menu");
Toast.makeText(getApplicationContext(), "응답으로 전달된 menu :" + menu, Toast.LENGTH_LONG).show();
}
}
}
public void login(View v){
EditText id=(EditText)findViewById(R.id.eid);
EditText pw=(EditText)findViewById(R.id.epw);

if(id.getText().toString().equals(userid)){
if (pw.getText().toString().equals(userpw)){
Intent intent=new Intent(getApplicationContext(),Main2Activity.class);
startActivityForResult(intent,REQUEST_CODE_MENU);
}
else Toast.makeText(MainActivity.this,"로그인 실패",Toast.LENGTH_LONG).show();
}
else Toast.makeText(MainActivity.this,"로그인 실패",Toast.LENGTH_LONG).show();
}

}

Main2Activity.java

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Main2Activity extends AppCompatActivity {

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

Button customerM=(Button)findViewById(R.id.customerM);
Button profitM=(Button)findViewById(R.id.profitM);
Button goodsM=(Button)findViewById(R.id.goodsM);

customerM.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("menu","customer");
setResult(RESULT_OK,intent);

finish();
}
});
profitM.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("menu","profit");
setResult(RESULT_OK,intent);

finish();
}
});
goodsM.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("menu","goods");
setResult(RESULT_OK,intent);

finish();
}
});
}
}

+ Recent posts