首页 > 其他分享 >每日总结2023/3.5

每日总结2023/3.5

时间:2023-03-05 10:45:25浏览次数:33  
标签:总结 adapterPl layout parent 3.5 2023 android id fill

4.单选按钮RadioGroup
RadioGroup提供的只是一个单选按钮的容器,只有在此容器中配置多个按钮组件之后才可以使用,设置单选按钮则需要使用RadioButton类

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFF00"
android:textSize="20pt"
android:text="你的求职意向"
/>
<RadioGroup
android:id="@+id/career"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:checkedButton="@+id/android">
<RadioButton
android:id="@+id/android"
android:text="Android"
/>
<RadioButton
android:id="@+id/Ios"
android:text="Iphone"
/>
</RadioGroup>

</LinearLayout>

5.复选框CheckBox
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFF00"
android:textSize="20pt"
android:text="你的特长:"
/>
<CheckBox
android:id="@+id/c1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text ="Unity3d"/>
<CheckBox
android:id="@+id/c2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text ="Android"/>
<CheckBox
android:id="@+id/c3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text ="IOS"/>

</LinearLayout>

public class MainActivity extends Activity {
 
    private CheckBox cb = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);
        this.cb = (CheckBox)super.findViewById(R.id.c1);
        cb.setChecked(true);
        cb.setText("OpenGL");
        
    }
 
    
 
}

6.下拉列表框Spinner
在Android中,可以直接在main.xml文件中定义<Spinner>节点,但是在定义此元素时却不能直接设置其显示的列表项。

1.直接通过资源配置文件配置

定义一个values\pl.xml 定义数据内容需要使用<string-array>元素指定

<resources>
<string-array name="pl_lables">
<item>C++</item>
<item>C#</item>
<item>Java</item>
</string-array>
</resources>

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
     <TextView
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFFF00"
        android:textSize="20pt"
        android:text="请选择你最喜欢的语言"
     />
     <Spinner 
         android:id="@+id/mypl"
         android:prompt="@string/pl_prompt"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:entries="@array/pl_lables"
         />
      
</LinearLayout>

如果配置文件没有读取下拉表数组内容配置文件,可以通过程序来控制

public class MainActivity extends Activity {
    private Spinner sppl = null;
    private ArrayAdapter<CharSequence> adapterPl= null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);
        this.sppl = (Spinner)super.findViewById(R.id.mypl);
        
        this.adapterPl = ArrayAdapter.createFromResource(this,R.array.pl_lables,android.R.layout.simple_spinner_item);
        this.adapterPl.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        this.sppl.setAdapter(this.adapterPl);
    }
 
    
 
}

如果不存在下拉列表内容的配置文件,也可以通过程序来实现

public class MainActivity extends Activity {
    private Spinner sppl = null;
    private ArrayAdapter<CharSequence> adapterPl= null;
    private List<CharSequence> dataEdu = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);
        this.dataEdu = new ArrayList<CharSequence>();
        this.dataEdu.add("C++");
        this.dataEdu.add("C#");
        this.dataEdu.add("Java");
        this.sppl = (Spinner)super.findViewById(R.id.mypl);
        
        this.adapterPl = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item,this.dataEdu);
        this.adapterPl.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        this.sppl.setAdapter(this.adapterPl);
    }
 
}

时间选择器

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
     <TimePicker
        android:id="@+id/tp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     />
      <TimePicker
        android:id="@+id/tp2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     />
    
</LinearLayout>
public class MainActivity extends Activity {
    private TimePicker tp = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);
        this.tp = (TimePicker)super.findViewById(R.id.tp1);
        tp.setIs24HourView(true);
        tp.setCurrentHour(11);
        tp.setCurrentMinute(42);
    }
 
}

组件默认的是十二小时制的,可以通过程序设置二十四小时制,并设定时间

日期选择器

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
     <DatePicker
        android:id="@+id/dp1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     />
      <DatePicker
        android:id="@+id/dp2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
     />
    
</LinearLayout>

 


原文链接:https://blog.csdn.net/Fatestay_DC/article/details/48516853

标签:总结,adapterPl,layout,parent,3.5,2023,android,id,fill
From: https://www.cnblogs.com/azwz/p/17179992.html

相关文章

  • 2023/3/3每日总结
    设置视图的宽高>视图宽度通过属性android:layoutwidth表达,视图高度通过属性android:layoutheioht表达,宽高的取值主要有下列三种:matchparent:表示与上级视图保持一致wr......
  • Qt插件开发总结5--主界面嵌入插件UI
    文章目录​​一、前言​​​​二、效果展示​​​​三、嵌入插件UI​​​​1、插件接口文件添加UI指针​​​​2、插件子项目工程建立UI类​​​​3、插件类中创建UI类、使U......
  • THUPC2023 游记
    回首曾经在THU打的三场比赛,仿佛是很久以前的事情了。如今的我可能是仍不愿走出舒适区,可能是畏惧曾经的OI水平已退化为“自然语言翻译器”或者“经典套路识别器”,可能......
  • Java实战(第二版)读后总结与感想
    1. 基本信息Java实战(第二版)ModernJavainAction,2ndEdition[英]拉乌尔–加布里埃尔·乌尔玛(Raoul-GabrielUrma),[意]马里奥·富斯科(MarioFusco),[英]艾伦·米克......
  • NOI2023春测游记
    DAY-?教练跟我们说让我们参加下春季赛,被迫参加(本来自己就太菜了)迫不得已就去秦皇岛吧DAY-1这天一直在做DP,感觉脑子快炸了不过DP感觉好多了DAY0准备出发了(打了打......
  • day04(2023.3.4)
    1.类型自动转换2.强制转换已及强制转换会出现的问题 3.键盘输入 4.台球小项目  台球小项目运行截图: 5.台球所用的素材:  写了个小小的台球游戏,还......
  • 2023/03/04刷题
    C.AndrewandStones链接C.AndrewandStones这个题还是比较有意思的,每天再补A.Array链接A.Array这个题比较好做可以发现要想条件成立的话,必须存在一个0.所以......
  • NOI 2023 春季测试 游记
    开坑,待填。upd:寄了,不想填,但还是来填坑了。\(Day-1\)看板子,什么都不会。(悲)\(Day0\)睡了一天觉,晚上和学长们玩了各种游戏/se。\(Day1\)早上起来感觉隐隐约约肚......
  • 「2023/02」学习记录
    这次只写了部分题(包括1月写的非WC题)。模拟赛题均没写。有亿点小鸽。这篇甚至能叫CF杂题乱做()。快省选了,看看怎么调整可以提升最大吧。「CF57E」Chess一个无限大......
  • 春季测试 2023 幂次
    **F出原题\(3\lek\)时,\(a\le10^6\)可以暴力统计答案,对于重复的贡献可以用类似筛法的东西去维护,因为每个数只会被筛一次,所以是\(O(n)\)的,但是统计答案要带一个常数。......