package jp.gihyo.mitoma.android.p022widgetstest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

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

        ButtonOnClick clickListener = new ButtonOnClick();
        Button btRegist = findViewById(R.id.btRegist);
        btRegist.setOnClickListener(clickListener);

        Button btUpdate = findViewById(R.id.btUpdate);
        btUpdate.setOnClickListener(clickListener);

        Button btDelete = findViewById(R.id.btDelete);
        btDelete.setOnClickListener(clickListener);

        Button btReturn = findViewById(R.id.btReturn);
        btReturn.setOnClickListener(clickListener);
    }
    private class ButtonOnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            String tag = v.getTag().toString();
            DialogFragment dialog = null;
            switch(tag){
                case "T10":
                    //登録処理
                    dialog =new RegistFragment();
                    break;
                case "T11":
                    //更新処理
                case "T12":
                    //削除処理
                case "T13":
                    //戻る処理
                default:
                    break;
            }
            if(dialog != null) {
                dialog.show(getSupportFragmentManager(), null);
            }
        }
    }
}