2012年10月7日日曜日

lesson13



********************  MainActivity.java  ********************
package jp.lesson.study10;
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit);
    }
    public void onClickButton(View view) {
        switch(view.getId()){
            case R.id.button1:{
                AlertDialog.Builder dlg = new AlertDialog.Builder(this);
                dlg.setTitle(getString(R.string.lbSaveTitle));
                dlg.setPositiveButton(getString(R.string.lbYes),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO 自動生成されたメソッド・スタブ
                            // 保存処理
                            finish();
                        }
                    });
                dlg.setNegativeButton(getString(R.string.lbNo),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO 自動生成されたメソッド・スタブ
                            // キャンセル
                        }
                    });
                dlg.show();
            }break;
            case R.id.button2:{
                finish();
            }break;
        }
    }
}

********************  edit.xml  ********************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
        android:text=""
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:fillViewport="true" >
        <EditText
            android:gravity="top"
            android:text=""
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </EditText>
    </ScrollView>
    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/lbSave"
            android:onClick="onClickButton" />
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/lbCancel"
            android:onClick="onClickButton" />
    </LinearLayout>
</LinearLayout>

********************  strings.xml  ********************
<resources>
    <string name="app_name">Study10</string>
    <string name="hello_world">hello</string>
    <string name="menu_settings">menu</string>
    <string name="title_activity_main">MainActivity</string>
   
    <string name="lbSave">保存</string>
    <string name="lbCancel">キャンセル</string>
    <string name="lbSaveTitle">保存確認</string>
    <string name="lbYes">はい</string>
    <string name="lbNo">いいえ</string>
</resources>


0 件のコメント:

コメントを投稿