今天的收获颇大呀,我发现了一个更高效快速的学习方法,如果真的是因为学习内容太多,无从下手的话,不妨去别人或者自己崇拜的大佬里的博客园里面转一转,你就会有意外的收获,不仅给你学习的压力,还更直观的给介绍了学习的方向和重点,这真的是捷径,我们要学会观看别人的博客园,从里面找到重点,获得收获。像一些零散的知识点里面都罗列的特别的详细,大佬就是大佬,总有我们崇拜的理由。在一位大佬的博客园里我看到了几个有趣的简易的app,感觉很有趣,就学习了一下。下面的内容我就是学习大佬之精华:

并且为了保存和加强对GitHub的学习,并且把一下代码上传到了GitHub上面,命名(playtest_married):

婚姻建议程序:

一:单选框按钮样例(RadioGroup和RadioButton建立单选框按钮)

strings.xml:

<resources>
<string name="app_name">婚姻建议程序app</string>
<string name="sex">性别</string>
<string name="age">年龄</string>
<string name="btn_ok">确定</string>
<string name="result">建议:</string>
<string name="not_hurry">青春还很富裕,先奋斗,结婚还不急!</string>
<string name="find_couple">时候到了,可以尝试找个对象了!</string>
<string name="get_married">你已经事业有成了,该结婚了!</string>
<string name="boy">男生</string>
<string name="gril">女生</string>
<string name="boy_age_1">小于25岁</string>
<string name="boy_age_2">25岁到30岁</string>
<string name="boy_age_3">大于30岁</string>
<string name="gril_age_1">小于25岁</string>
<string name="gril_age_2">25岁到30岁</string>
<string name="gril_age_3">大于30岁</string>
</resources>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> <TextView
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sex"
android:textSize="25sp" />
<RadioGroup
android:id="@+id/radgrpsex"
android:checkedButton="@+id/radbtnboy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radbtnboy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/boy"/>
<RadioButton
android:id="@+id/radbtngril"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/gril"/>
</RadioGroup>
<TextView
android:id="@+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/age"
android:textSize="25sp"/> <RadioGroup
android:id="@+id/radgrpage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:checkedButton="@+id/radbtnage1"> <RadioButton
android:id="@+id/radbtnage1"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy_age_1"/>
<RadioButton
android:id="@+id/radbtnage2"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy_age_2"/>
<RadioButton
android:id="@+id/radbtnage3"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy_age_3"/>
</RadioGroup>
<Button
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#4CAF50"
android:text="@string/btn_ok"/>
<TextView
android:id="@+id/txtresult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="25sp"/> </LinearLayout>

MainActivity.java:

package com.example.playtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private Button mbtnok;
private TextView mtxtr;
private RadioGroup mradgrpsex,mradgrpage;
private RadioButton mradbtnage1,mradbtnage2,mradbtnage3; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mbtnok=(Button)findViewById(R.id.btn_ok);
mbtnok.setOnClickListener(btnokOnClick);
mtxtr=(TextView)findViewById(R.id.txtresult);
mradgrpage=(RadioGroup)findViewById(R.id.radgrpage);
mradgrpsex=(RadioGroup)findViewById(R.id.radgrpsex);
mradbtnage1=(RadioButton) findViewById(R.id.radbtnage1);
mradbtnage2=(RadioButton) findViewById(R.id.radbtnage2);
mradbtnage3=(RadioButton) findViewById(R.id.radbtnage3); mradgrpsex.setOnCheckedChangeListener(radgrpsexOnClickedChange);
} private View.OnClickListener btnokOnClick=new View.OnClickListener(){
@Override
public void onClick(View v){
String strres=getString(R.string.result); switch(mradgrpage.getCheckedRadioButtonId()){
case R.id.radbtnage1:
strres+=getString(R.string.not_hurry);break;
case R.id.radbtnage2:
strres+=getString(R.string.find_couple);break;
case R.id.radbtnage3:
strres+=getString(R.string.get_married);break;
}
mtxtr.setText(strres);
}
}; private RadioGroup.OnCheckedChangeListener radgrpsexOnClickedChange=new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group,int checkedid){
if(checkedid==R.id.radbtnboy){
mradbtnage1.setText(getString(R.string.boy_age_1));
mradbtnage2.setText(getString(R.string.boy_age_2));
mradbtnage3.setText(getString(R.string.boy_age_3));
}
else{
mradbtnage1.setText(getString(R.string.gril_age_1));
mradbtnage2.setText(getString(R.string.gril_age_2));
mradbtnage3.setText(getString(R.string.gril_age_3));
}
}
};
}

运行结果显示:

二:下拉框(Spinner)和数字转轮(NumberPicker)的使用

这个是在上面的婚姻建议程序app的基础上改的,将其换成了下拉框和数字转轮的形式

strings.xml:

<resources>
<string name="app_name">婚姻建议程序app</string>
<string name="sex">性别</string>
<string name="age">年龄</string>
<string name="btn_ok">确定</string>
<string name="result">建议:</string>
<string name="not_hurry">青春还很富裕,先奋斗,结婚还不急!</string>
<string name="find_couple">时候到了,可以尝试找个对象了!</string>
<string name="get_married">你已经事业有成了,该结婚了!</string>
<string name="boy">男生</string>
<string-array name="sex_list">
<item>男生</item>
<item>女生</item>
</string-array>
<string name="sex_select">请选择性别:</string>
<string name="boy_age_1">小于25岁</string>
<string name="boy_age_2">25岁到30岁</string>
<string name="boy_age_3">大于30岁</string>
<string name="gril_age_1">小于25岁</string>
<string name="gril_age_2">25岁到30岁</string>
<string name="gril_age_3">大于30岁</string>
</resources>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> <TextView
android:id="@+id/sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sex"
android:textSize="25sp" />
<Spinner
android:id="@+id/spnsex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/sex_list"
android:spinnerMode="dialog"
android:prompt="@string/sex_select"/>
<TextView
android:id="@+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/age"
android:textSize="25sp"/>
<TextView
android:id="@+id/txtage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"/>
<NumberPicker
android:id="@+id/numage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/> <Button
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#4CAF50"
android:text="@string/btn_ok"/>
<TextView
android:id="@+id/txtresult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="25sp"/> </LinearLayout>

MainActivity.java:

package com.example.playtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.Spinner;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private NumberPicker numage;
private Spinner spsex;
private Button mbtnok;
private TextView mtxtresult,mtxtage;
private String strsex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mtxtage=(TextView)findViewById(R.id.txtage);
mtxtage.setText("25"); numage=(NumberPicker)findViewById((R.id.numage));
numage.setMinValue(0);
numage.setMaxValue(100);
numage.setValue(25);
numage.setOnValueChangedListener(numChange); mbtnok=(Button)findViewById(R.id.btn_ok);
mbtnok.setOnClickListener(btnonClick); mtxtresult=(TextView)findViewById(R.id.txtresult);
spsex=(Spinner)findViewById(R.id.spnsex);
spsex.setOnItemSelectedListener(spsexOnItemSelected);
} private View.OnClickListener btnonClick=new View.OnClickListener() {
@Override
public void onClick(View v) {
int age=numage.getValue();
String strresult=getString(R.string.result); if(age<25)
strresult+=getString(R.string.not_hurry);
else if(age>30)
strresult+=getString(R.string.get_married);
else
strresult+=getString(R.string.find_couple);
mtxtresult.setText(strresult);
}
}; private AdapterView.OnItemSelectedListener spsexOnItemSelected=new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
strsex=parent.getSelectedItem().toString();
} @Override
public void onNothingSelected(AdapterView<?> parent) { }
}; private NumberPicker.OnValueChangeListener numChange=new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mtxtage.setText(String.valueOf(newVal));
}
};
}

运行结果:

App基本界面组件案例的更多相关文章

  1. 四种常见的APP分类界面布局设计案例学习

    相信各位对于APP设计,已经很熟练啦.如何在熟练的基础上提高我们界面的优美度,或者是进行APP界面的迭代设计. 重构APP设计布局是我们必须要经历的一个过程. 在之前,学习UI设计的时候,经常要接触到 ...

  2. App 引导界面

    App 引导界面 1.前言 最近在学习实现App的引导界面,本篇文章对设计流程及需要注意的地方做一个浅显的总结. 附上项目链接,供和我水平类似的初学者参考——http://files.cnblogs. ...

  3. ionic入门之色彩、图标、边距和界面组件:列表

    目录: 色彩.图标和边距 色彩 图标 内边距 界面组件:列表 列表:.list 成员容器:.item .item: 嵌入文本 .item : 嵌入图标 .item : 嵌入头像 .item : 嵌入缩 ...

  4. 精华 ionic入门之色彩、图标、边距和界面组件:列表

    目录:色彩.图标和边距色彩图标内边距界面组件:列表列表:.list成员容器:.item.item: 嵌入文本.item : 嵌入图标.item : 嵌入头像.item : 嵌入缩略图.item : 嵌 ...

  5. 前端笔记之Vue(二)组件&案例&props&计算属性

    一.Vue组件(.vue文件) 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器 ...

  6. 循序渐进VUE+Element 前端应用开发(25)--- 各种界面组件的使用(1)

    在我们使用Vue+Element开发前端的时候,往往涉及到很多界面组件的使用,其中很多直接采用Element官方的案例即可,有些则是在这个基础上封装更好利用.更少代码的组件:另外有些则是直接采用第三方 ...

  7. 循序渐进VUE+Element 前端应用开发(26)--- 各种界面组件的使用(2)

    在我们使用Vue+Element开发前端的时候,往往涉及到很多界面组件的使用,其中很多直接采用Element官方的案例即可,有些则是在这个基础上封装更好利用.更少代码的组件:另外有些则是直接采用第三方 ...

  8. Android界面组件的四种启动方式

    Android界面组件启动有四种方式 standard,singleTop,singleTask,singleInstance. standard:每次调用都会都会产生新的组件. singletop: ...

  9. 安卓开发_慕课网_Fragment实现Tab(App主界面)

    学习内容来自“慕课网” 这里用Fragment来实现APP主界面 思路: 底部横向排列4个LinearLayout,每个LinearLayout包含一个图片按钮和一个文字 1.默认显示第一个功能(微信 ...

随机推荐

  1. {$DEFINE WANYI}

    var Form5: TForm5; {$DEFINE WANYI}implementation{$R *.dfm}procedure TForm5.Button1Click(Sender: TObj ...

  2. burpsite 和jdk的配置

    最近小白再安装工具,首先是java的jdk,小白的电脑重装系统之后以前装的就没有了,然后记性不好的小白就开始百度了,百度上说是需要配置java_home和classpath路径然后再去编辑path路径 ...

  3. element设置headers添加token

    <template>   <div>     <el-upload       action="http://localhost:3000/picture&qu ...

  4. LOJ #10002. 喷水装置

    题目 裸的贪心. 基本思想见图: Code: #include<iostream> #include<cstdio> #include<cstring> #incl ...

  5. mysql导入导出无权限

    error:The MySQL server is running with the --secure-file-priv option so it cannot execute this state ...

  6. 031、Java中偶数偶数的判断方法

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  7. leetcode1143 Longest Common Subsequence

    """ Given two strings text1 and text2, return the length of their longest common subs ...

  8. DFS技巧 折半搜索

    #include<iostream> #include<string> #include<cmath> #include<cstring> #inclu ...

  9. python_os 的知识点

    1. os.getcwd() #获得当前路径 2. os.listdir(path) #列出path路径下的所有目录名和文件名包括后缀 3. os.mkdir(path) #在path创建一个目录 4 ...

  10. Kafka--windows下简单使用kafka命令

    参考 https://www.cnblogs.com/cici20166/p/9426417.html 启动zookeeper 只需要保证有可用的zookeeper,可以使用kafka内置的,也可以自 ...