当前位置:首页 > android常用控件总结
main.xml
android:id=\ android:layout_width=\ android:layout_height=\ android:text=\ /> android:id=\ android:layout_width=\ android:layout_height=\ android:orientation=\ android:layout_x=\ android:layout_y=\ > android:id=\ android:layout_width=\ android:layout_height=\ android:text=\ /> android:id=\ android:layout_width=\ android:layout_height=\ android:text=\ /> android:id=\ android:layout_width=\ android:layout_height=\ android:text=\ /> android:id=\ android:layout_width=\ android:layout_height=\ android:text=\ /> public class Activity01 extends Activity{ TextView m_TextView; RadioGroup m_RadioGroup; RadioButton m_Radio1, m_Radio2, m_Radio3, m_Radio4; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); m_RadioGroup = (RadioGroup) findViewById(R.id.RadioGroup01);//获得RadioGroup对象 m_Radio1 = (RadioButton) findViewById(R.id.RadioButton1);//获得4个RadioButton对象 m_Radio2 = (RadioButton) findViewById(R.id.RadioButton2); m_Radio3 = (RadioButton) findViewById(R.id.RadioButton3); m_Radio4 = (RadioButton) findViewById(R.id.RadioButton4); /* 设置事件监听 */ m_RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {---------------------------RadioGroup监听器 @Override public void onCheckedChanged(RadioGroup group, int checkedId){ if (checkedId == m_Radio2.getId()){ DisplayToast(\正确答案:\+ m_Radio2.getText() + \,恭喜你,回答正确!\ }else{ DisplayToast(\请注意,回答错误!\ } } }); } public void DisplayToast(String str)//显示Toast{ Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG); //设置toast显示的位置 toast.setGravity(Gravity.TOP, 0, 220); //显示该Toast toast.show(); } } ----------------------------------------------------------------------------------------------------------- AutoCompletTextView 和MultiAutoCompleteTextView 作用:自动提示 下面例中用到了ArrayAdapter autoCompletTextView.xml android:id= \ android:layout_width=\ android:layout_height=\ /> android:id= \ android:layout_width=\ android:layout_height=\ /> //如何实现如果输入的字符不在其范围内的也能得到提示 是继承TextWatcher? public class Control_Auto extends Activity { //implements TextWatcher{} public TextView textView_auto; private static final String[] string ={\hao\hao \hao ma\zheng de hao ma\ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.autocompletetextview); //将可选内容与适配器ArrayAdapter连接
共分享92篇相关文档