Android学习笔记7——常用控件
2010-11-11 00:45
351 查看
1.TextView
2.EditView
3.Button
4.RadioButton
5.Checkbox
6.Toast
7.ProgressBar
8.ListView
4.RadioButton
需结合布局文件里需结合RadioGroup使用
复写listener的函数跟Button的稍许不同,跟设置的连在一起,跟checkbox类似
5.Checkbox
复写listener的函数跟Button的稍许不同,跟设置的连在一起,跟RadioButton类似
同时注意的是,checkbox集成了CompoundButton的listener,它自己没有listener
6.Toast
弹出的msgbox,一回会消失
7.ProgressBar
有两种,一种横的,一种圆的
横的可以显示进度,圆的一直在转
8.ListView
1)新建一个Arraylist,然后插到Adapter里面
关键是ArrayList的理解,
结构
ArrayList
HashMap
String,String(键值对)
2)需要两个xml,一个是listActivity,一个是list里面的textView布局
listAct.java
listact.xml(注意要用小写,听说,否则R.java不能生成)
listuser.xml(是list里面的textview布局)
效果图(点击瞬间)
2.EditView
3.Button
4.RadioButton
5.Checkbox
6.Toast
7.ProgressBar
8.ListView
4.RadioButton
需结合布局文件里需结合RadioGroup使用
RGrp_Methods = (RadioGroup)findViewById(R.id.RGrp_Methods); RBtn_Multiply = (RadioButton)findViewById(R.id.RBtn_Multiply); RBtn_Divide = (RadioButton)findViewById(R.id.RBtn_Divide); RBtn_Add = (RadioButton)findViewById(R.id.RBtn_Add); RBtn_Minus = (RadioButton)findViewById(R.id.RBtn_Minus); RGrp_Methods.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub } });
复写listener的函数跟Button的稍许不同,跟设置的连在一起,跟checkbox类似
5.Checkbox
ToastOrIntent = (CheckBox)findViewById(R.id.ToastOrIntent); ToastOrIntent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub System.out.println("CheckBox -> ToastOrIntent"); Toast.makeText(hello.this, R.string.str_UseToast, Toast.LENGTH_SHORT).show(); } });
复写listener的函数跟Button的稍许不同,跟设置的连在一起,跟RadioButton类似
同时注意的是,checkbox集成了CompoundButton的listener,它自己没有listener
6.Toast
弹出的msgbox,一回会消失
Toast.makeText(hello.this, R.string.str_UseToast, Toast.LENGTH_SHORT).show();
7.ProgressBar
有两种,一种横的,一种圆的
横的可以显示进度,圆的一直在转
8.ListView
1)新建一个Arraylist,然后插到Adapter里面
关键是ArrayList的理解,
结构
ArrayList
HashMap
String,String(键值对)
2)需要两个xml,一个是listActivity,一个是list里面的textView布局
setContentView(R.layout.listact); ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>(); HashMap<String,String> map1 =new HashMap<String,String>(); HashMap<String,String> map2 =new HashMap<String,String>(); HashMap<String,String> map3 =new HashMap<String,String>(); map1.put("user_name", "胡锦涛"); map1.put("user_num", "13456789012"); map2.put("user_name", "奥巴马"); map2.put("user_num", "14567890123"); map3.put("user_name", "我"); map3.put("user_num", "15678901234"); list.add(map1); list.add(map2); list.add(map3); SimpleAdapter listAdapter = new SimpleAdapter(this, list, R.layout.listuser, new String[]{"user_name", "user_num"}, new int[]{R.id.user_name, R.id.user_num}); setListAdapter(listAdapter);
listAct.java
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:id="@+id/ListLinearLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@id/android:list" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent" android:scrollbars="vertical" android:drawSelectorOnTop = "false" > </ListView> </LinearLayout> </LinearLayout>
listact.xml(注意要用小写,听说,否则R.java不能生成)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <TextView android:id="@+id/user_name" android:layout_width="180dip" android:layout_height="30dip" android:textSize="10pt" android:singleLine="true" /> <TextView android:id="@+id/user_num" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="10pt" /> </LinearLayout>
listuser.xml(是list里面的textview布局)
效果图(点击瞬间)
相关文章推荐
- Android学习笔记(五)常用控件上
- android学习笔记之一常用控件
- Android学习笔记-常用控件
- Android学习笔记(三)——常用控件的学习
- Android学习笔记:<二>03.Android当中的常用控件
- Android学习笔记--Android开发时常用控件(三)
- android学习笔记之一常用控件
- Android学习笔记之(三):UI(1)常用控件
- Android学习笔记03——常用控件的使用
- Android学习笔记(五)常用控件ToggleButton
- Android学习笔记(五)常用控件下
- Android学习笔记7——常用控件ProgressBar
- Android学习笔记:常用控件 RadioGroup和CheckBox
- Android学习笔记之常用控件
- Android学习笔记8——常用控件ListView
- Android学习笔记(五)常用控件上
- Android学习笔记---常用控件
- android学习笔记(二)—— 常用布局与控件
- Android学习笔记(五)常用控件中
- Android学习笔记(五)常用控件中