/* relativelayout.java */
package com.example.relativelayout;
import android.os.Bundle;
import android.app.Activity;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date();
String nowDate = dateFormat.format(date);
TextView dateView = (TextView)findViewById(R.id.dates);
dateView.setText(nowDate);
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
String nowTime = timeFormat.format(date);
TextView timeView = (TextView)findViewById(R.id.times);
timeView.setText(nowTime);
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu;
getMenuInflater().inflate(R.menu.main, menu); return true;
}
}
//* Activity_main.xml */
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
<TextView
android:id="@+id/dates"
android:layout_width="0dp"
android:layout_below="@id/name"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" />
<TextView
android:id="@id/times"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true" />
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_alignTop="@id/ok"
android:text="Cancel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/ok"
android:layout_below="@+id/entry"/>
</RelativeLayout>
0 comments:
Post a Comment