A sentimental robot

Activity 본문

Android Studio

Activity

GOD03219 2018. 1. 31. 13:09

//activity_main.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#aaaaaa"
android:orientation="vertical"
android:gravity="center"
tools:context="com.example.i310_54.myapplication01.MainActivity">





<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="push"
android:background="#ff0d00"
android:onClick="f1"/>


</LinearLayout>

// MainActivity.java

 

package com.example.i310_54.myapplication01;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.DataSetObserver;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


@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);

Button button2=findViewById(R.id.button2);

String na1=Integer.toString(data.getIntExtra("res",0));
button2.setText(na1+"초");


}

public void f1(View view) {


Intent intent=new Intent(getApplicationContext(),AppleActivity.class);
Calendar c = Calendar.getInstance();


int h=c.get(Calendar.HOUR);
int m=c.get(Calendar.MINUTE);
int s=c.get(Calendar.SECOND);
int d=c.get(Calendar.DAY_OF_WEEK);

Log.v("test",h+" "+m);
String ar[]=new String[]{"일","월","화","수","목","금","토"};


intent.putExtra("h",h);
intent.putExtra("m",m);
intent.putExtra("s",s);
intent.putExtra("d",ar[d-1]);

startActivityForResult(intent,101);


}


}

// activity_apple.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#aaaaaa"
android:orientation="horizontal"
tools:context="com.example.i310_54.myapplication01.AppleActivity">



<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="previous page"
android:onClick="f1"
/>


</LinearLayout>
// AppleActivity.java

package com.example.i310_54.myapplication01;

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

import java.util.Calendar;

public class AppleActivity extends AppCompatActivity {

int h;
int m;
int s;
int d;
String date;
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apple);

Intent intent=getIntent();
h=intent.getIntExtra("h",0);
m=intent.getIntExtra("m",0);
s=intent.getIntExtra("s",0);
d=intent.getIntExtra("d",0);
date=intent.getStringExtra("d");

Button button3=findViewById(R.id.button3);
button3.setText(date+"요일"+h +"시 "+m+"분 "+s+"초");





}

public void f1(View view){

Intent intent=new Intent();
int ah=h*3600;
int am=m*60;
int res=ah+am+s;


intent.putExtra("res",res);


setResult(1000,intent);
finish();
}


}
// AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.i310_54.myapplication01">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="zombie"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AppleActivity"
android:label="apple"
android:theme="@style/AppTheme">

</activity>
</application>

</manifest>


 


 


 

'Android Studio' 카테고리의 다른 글

TableLayout  (0) 2018.02.01
Transmission  (0) 2018.01.31
Activity transition/intent  (0) 2018.01.30
ListView  (0) 2018.01.29
Spinner  (0) 2018.01.29