Android 列表对话框

Android 列表对话框_第1张图片

package com.example.test9;

import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

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

	public void btn1Onclick(View view){
		final String[] items={"AAA","BBB","CCC","DDD"};
		AlertDialog dlg=new AlertDialog.Builder(this)
		.setIcon(R.drawable.ic_launcher)
		.setTitle("列表对话框")
		.setItems(items, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				Toast.makeText(MainActivity.this, items[which], Toast.LENGTH_LONG).show();
			}
		})
		.show();
	}
}

你可能感兴趣的:(android)