android 各种常用,不易记的dialog,等控件整理
[java]
package com.su.testalldialog;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInte易做图ce;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
public class TestAllDialogActivity extends Activity {
String[] weekdays;
Context context;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context = this;
weekdays = new String[] { "Sun", "Mon", "Tue", "Wed" };
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);
Button button4 = (Button) findViewById(R.id.button4);
Button button5 = (Button) findViewById(R.id.button5);
Button button6 = (Button) findViewById(R.id.button6);
button6.setOnClickListener(listener);
button5.setOnClickListener(listener);
button1.setOnClickListener(listener);
button2.setOnClickListener(listener);
button3.setOnClickListener(listener);
button4.setOnClickListener(listener);
initSpinner();
initAutocompletetextview();
}
private void initAutocompletetextview() {
AutoCompleteTextView autocompletetextview = (AutoCompleteTextView) findViewById(R.id.autocompletetextview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
android.R.layout.易做图_spinner_dropdown_item, weekdays);// 实现简单的adapter
autocompletetextview.setAdapter(adapter);
}
private void initSpinner() {
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(slistener);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
android.R.layout.易做图_spinner_item, weekdays);// 实现简单的adapter
adapter.setDropDownViewResource(android.R.layout.易做图_spinner_dropdown_item);// 实现选项的样式
spinner.setAdapter(adapter);
}
private OnItemSelectedListener slistener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
toast(weekdays[arg2]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
};
int index = 0;// 用来标记哪一项被选择
private OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
Builder dialog = new AlertDialog.Builder(context);
switch (v.getId()) {
case R.id.button1:
dialog.setIcon(R.drawable.ic_launcher);
dialog.setTitle("简单选择对话框");
dialog.setItems(weekdays,
new DialogInte易做图ce.OnClickListener() {
@Override
public void onClick(DialogInte易做图ce dialog,
int which) {
toast(weekdays[which]);
}
&
补充:移动开发 , Android ,