activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="다이얼 로그 보이기" />
</RelativeLayout>
MainActivity.java
package com.example.dialogex01;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.TextureView;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new AlertDialog.Builder(MainActivity.this)
.setTitle("타이틀")
.setItems(new String[]{"짜장면","짬뽕","우동","탕수육"},
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "선택한 위치 :" +
which, Toast.LENGTH_SHORT).show();
}
})
.setIcon(R.drawable.ic_launcher)
.setNegativeButton("취소", null)
.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
'Android' 카테고리의 다른 글
대화상자 - MultiChoiceItems (0) | 2013.04.02 |
---|---|
대화상자 - SingleChoiceItems (0) | 2013.04.02 |
대화상자 - AlertDialog (0) | 2013.04.02 |
대화상자 - Dialog (0) | 2013.04.02 |
기타위젯 - WebView (0) | 2013.04.02 |