android app小白试水6-button&toast
来源:互联网 发布:python爬虫怎样赚外快 编辑:程序博客网 时间:2024/05/28 18:44
这一节其实是要做一个手机端的表单,供用户进行填写。最后的成品应该是这样的:
由于是做成竖版的排版,因此可以直接将fragment_main.xml中的标签RelativeLayout 改成<LinearLayout>并且指明是竖版排版:
android:orientation="vertical"然后从控件区域添加不同的text控件。注意由于不同的text控件会出现不同的输入法键盘,因此需要添加不同类型的text控件。每一个控件可以添加hint来标识提示性的文字:
android:hint="a simple password"
fragment_main.xml的代码如下:
<EditText android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPersonName" android:hint="@string/your_full_name">] <requestFocus /> </EditText> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPassword" android:hint="a simple password"/> <EditText android:id="@+id/phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="phone" android:hint="your phone number"/> <EditText android:id="@+id/email" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textEmailAddress" android:hint="your email address"/> <ImageButton android:id="@+id/survey" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="formProcess" android:src="@drawable/ic_launcher" />注意在其中为每个ID添加了可读性更强的文字,另外还添加了imageButton以便提交用户填写的信息。
接下来便是为imagebutton添加onclick动作。每次涉及到前端和后台交互时由于使用fragment都会出现bug,因为老师在不使用fragment的时候的确方便简单很多。
像老师一样在onCreate中添加了onclick的代码:
public void formProcess(View submit){ submit.setVisibility(View.INVISIBLE);}
后来运行果然出现了bug啊!妥妥的:
后来了解到在fragment使用进行交互时要使用监听模式,并且交互代码要写在fragment的代码段中进行交互:
于是在onCreateView中添加如下代码:
ImageButton surveyB = (ImageButton)rootView.findViewById(R.id.survey);OnClickListener listener0 = null; listener0 = new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubv.setVisibility(View.INVISIBLE);} }; surveyB.setOnClickListener(listener0);return rootView;
果然能够顺利的实现功能了呢~
最后添加了Toast:
Toast.makeText(v.getContext(), R.string.your_full_name,Toast.LENGTH_LONG).show();
0 0
- android app小白试水6-button&toast
- Android(Toast#Menu#Button)
- Android APP开发入门教程-Button
- Android入门笔记 - 界面开发 - TextView,Button,EditText,Toast
- Android学习笔记之Button,Toast,menu的简单用法
- android多次点击button只弹一次toast
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- Android基础教程(三)之-----简单的Button事件响应综合提示控件Toast的应用
- Android教程(五)-- Button控件配合Toast控件的使用
- Android基础教程之简单的Button事件响应综合提示控件Toast的应用
- android Toast
- android Toast
- android Toast
- Android--Toast
- android Toast
- VS编译Lua5.3动态库
- web.xml配置文件详解
- Algorithm One Day One -- 约瑟夫环(丢手绢问题)
- ajax async属性值
- android-support-v7-appcompat.jar包的引用
- android app小白试水6-button&toast
- shark 部署与演示《二》
- Flex项目转AIR技巧
- Xcode6在iPhone5+iOS7模拟器上编译,上下有黑边问题
- UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
- ViewPager+RadioButton+FragmentPagerAdapter实现导航fragment生命周期分析
- android多国语言 国际化
- 在iOS中使用第三方类库
- vlc缓冲事件添加及缓冲进度