Toast信息提示框
bt1.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(To.this, "短时间", Toast.LENGTH_SHORT).show(); tView.setText("短时间"); } }); bt2.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(To.this, "长时间", Toast.LENGTH_LONG).show(); tView.setText("长时间"); } });
AlertDialg警告框
bt3.setOnClickListener(new OnClickListener() { public void onClick(View v) { Dialog ad=new AlertDialog.Builder(To.this) .setTitle("警告")//设置标题 .setIcon(R.drawable.icon)//设置图片 .setMessage("提示警告")//设置提示信息 .create(); ad.show(); } });
ProgressDialog进度处理框
bt4.setOnClickListener(new OnClickListener() { public void onClick(View v) { final ProgressDialog proDia=ProgressDialog .show(To.this, "搜索信号", "请耐心等待~~~"); new Thread(){ public void run(){ try { Thread.sleep(3000);//运行3秒后关闭对话框 } catch (Exception e) { // TODO: handle exception }finally{ proDia.dismiss();//关闭对话框 } } }.start(); //线程启动 proDia.show();//显示对话框 } });
SeekBar拖动条
sb.setProgress(60);//固定进度 sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar seekBar) { tView.append("结束拖动"+seekBar.getProgress()); } public void onStartTrackingTouch(SeekBar seekBar) { tView.append("开始拖动"+seekBar.getProgress()); } public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tView.append("拖动进度"+progress); } });
ListView列表视图
<ListView android:layout_width="fill_parent" android:entries="@array/city" android:layout_height="wrap_content" android:background="#ff0000" ></ListView>
SimpleAdapter类设置列表视图
public class Simple extends Activity { private List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.si); ListView lv=(ListView)findViewById(R.id.lv); String [] data=getResources().getStringArray(R.array.city); for (int i = 0; i < data.length; i++) { Map<String, Object> map=new HashMap<String, Object>(); map.put("photoId", R.drawable.ss); map.put("data", data[i]); list.add(map); } SimpleAdapter adapter= new SimpleAdapter(this, list, R.layout.simple, new String[]{"photoId","data"}, new int[]{R.id.lv,R.id.TextView01}); lv.setAdapter(adapter); } }