第一范文网 - 专业文章范例文档资料分享平台

android常用控件总结

来源:用户分享 时间:2025/5/21 23:26:55 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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连接

搜索更多关于: android常用控件总结 的文档
android常用控件总结.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c26sg356o8q3fmdy9vdat_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top