# my-android-study
**Repository Path**: M00nBack/my-android-study
## Basic Information
- **Project Name**: my-android-study
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2021-04-18
- **Last Updated**: 2021-04-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 作业1-界面设计

## 说明
使用了约束布局
主要控件:TextView RadioButton FrameLayout ProgressBar
控件属性:
颜色相关
```
android:background="@color/back_blue"
android:textColor="@color/white"
```
内容相关
```
android:text="@string/title"
android:button="@drawable/button_a_select"
```
大小相关
```
android:layout_width="361dp"
android:layout_height="250dp"
android:textSize="19sp"
android:layout_marginTop="100dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
```
位置相关
```
android:gravity="center"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintLeft_toRightOf="parent"
```
进度条
```
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="68dp"
android:max="100"
android:progress="20" />
```
## 效果

# 作业2-基本控件使用

## 效果
主界面:


提交显示界面

## 界面布局、功能实现方法
### 界面布局
主界面主要包括:
ScrollView控件用于问题列表上下滑动进度条
TextView控件主要用于问题显示
问题答案单选使用RadioGroup包含多个RadioButton
多选则则使用CheckBox
接收输入文本内容则采用EditText
布局采用:LinearLayout
主界面xml文件:
```xml
```
调查问卷显示xml文件 主要使用了TextView控件:
```xml
```
### 功能实现方法
主界面实现的功能
1. 显示界面:这个没啥好说的 只需在onCreate方法使用setContentView方法给activity设置一个layout布局
2. 监听控件: 这里涉及了三种控件的监听方式RadioButton、CheckBox、EditText代码已经实现 具体参见代码
3. 存储数据:这里直接定义成员变量存储数据
4. 界面跳转 :这里使用内部类的方式
5. 数据传递:实现数据在多个activity中传递 这里用了Intent和Bundle
主界面代码:
```java
package com.example.myapp2;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MainActivity extends AppCompatActivity {
private Button button1;
private Button button2;
private submit_OnClickListener listener1;
private exit_OnClickListener listener2;
/*
传递给问卷显示页面的结果
*/
private String qs_study_android_res = "";
private String qs_speed_course_res = "";
private String qs_course_reverse_res = "";
private String qs_most_interest_res = "";
private String qs_suggest_res = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隐藏标题栏
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
setContentView(R.layout.activity_main);
StartListening();
}
/*
开始监听
*/
private void StartListening(){
button1 = findViewById(R.id.btn_submit);
button2 = findViewById(R.id.btn_exit);
listener1 = new submit_OnClickListener();
listener2 = new exit_OnClickListener();
button1.setOnClickListener(listener1);
button2.setOnClickListener(listener2);
StartListenRadioGroup(findViewById(R.id.qs_study_android));
StartListenRadioGroup(findViewById(R.id.qs_speed_course));
StartListenRadioGroup(findViewById(R.id.qs_course_reverse));
StartListenCheckBox(findViewById(R.id.qs_most_interest_a));
StartListenCheckBox(findViewById(R.id.qs_most_interest_b));
StartListenCheckBox(findViewById(R.id.qs_most_interest_c));
StartListenCheckBox(findViewById(R.id.qs_most_interest_d));
StartListenCheckBox(findViewById(R.id.qs_most_interest_e));
StartListenCheckBox(findViewById(R.id.qs_most_interest_f));
StartListenEditText(findViewById(R.id.qs_suggest));
}
/*
监听RadioGroup函数 并设置对应的返回值
*/
private void StartListenRadioGroup(RadioGroup radioGroup){
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup radioGroup, int id) {
RadioButton radiobutton = findViewById(radioGroup.getCheckedRadioButtonId());
switch (id){
case R.id.qs_study_yes:
case R.id.qs_study_no:
qs_study_android_res = radiobutton.getText().toString();
Log.v("DEBUG qs_study_android_res ", qs_study_android_res);
break;
case R.id.speed_fast:
case R.id.speed_mid:
case R.id.speed_slow:
qs_speed_course_res = radiobutton.getText().toString();
Log.v("DEBUG qs_speed_course_res ", qs_speed_course_res);
break;
case R.id.qs_add_yes:
case R.id.qs_add_no:
qs_course_reverse_res = radiobutton.getText().toString();
Log.v("DEBUG qs_course_reverse_res ", qs_course_reverse_res);
break;
}
}
});
}
/*
监听CheckBox 设置对应值
*/
private void StartListenCheckBox(CheckBox checkBox){
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
if (arg1) {
Log.v("DEBUG",checkBox.getText().toString());
/*
重复增加情况
*/
if(!qs_most_interest_res.contains(checkBox.getText().toString())){
qs_most_interest_res += checkBox.getText().toString()+"、";
}
Log.v("DEBUG",qs_most_interest_res);
}
/*
选过之后又不选的情况
*/
else{
if(qs_most_interest_res.contains(checkBox.getText().toString())){
qs_most_interest_res.replace(checkBox.getText().toString()+"\n","");
}
}
}
});
}
/*
监听EditText 设置对应值
*/
private void StartListenEditText(EditText editText){
editText.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
qs_suggest_res = editText.getText().toString();
Log.v("DEBUG",qs_course_reverse_res);
}
});
}
/*
用于确定跳转的类
*/
class submit_OnClickListener implements View.OnClickListener
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(MainActivity.this, QuestionResults.class);
Bundle bundle = new Bundle();
bundle.putString("qs_study_android_res",qs_study_android_res);
bundle.putString("qs_speed_course_res",qs_speed_course_res);
bundle.putString("qs_course_reverse_res",qs_course_reverse_res);
bundle.putString("qs_most_interest_res",qs_most_interest_res.substring(0,qs_most_interest_res.length() - 1));
bundle.putString("qs_suggest_res",qs_suggest_res);
intent.putExtras(bundle);
startActivity(intent);
}
}
/*
退出跳转的类
*/
class exit_OnClickListener implements View.OnClickListener
{
public void onClick(View v)
{
finish();
}
}
}
```
调查结果显示界面功能
1. 界面显示
2. 设置界面内容
3. 从bundle获取数据
调查结果显示界面代码:
```java
package com.example.myapp2;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import java.util.ArrayList;
import androidx.appcompat.app.ActionBar;
public class QuestionResults extends MainActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隐藏标题栏
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
setContentView(R.layout.question_results);
TextView qs_study_android_res = findViewById(R.id.qs_study_android_res);
TextView qs_speed_course_res = findViewById(R.id.qs_speed_course_res);
TextView qs_course_reverse_res = findViewById(R.id.qs_course_reverse_res);
TextView qs_most_interest_res = findViewById(R.id.qs_most_interest_res);
TextView qs_suggest_res = findViewById(R.id.qs_suggest_res);
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
String qs_study_android = bundle.getString("qs_study_android_res","");
String qs_speed_course = bundle.getString("qs_speed_course_res","");
String qs_course_reverse = bundle.getString("qs_course_reverse_res","");
String qs_most_interest = bundle.getString("qs_most_interest_res","");
String suggestion = bundle.getString("qs_suggest_res","");
qs_study_android_res.setText("1. 以前是否自学过安卓开发:\n\t\t\t"+qs_study_android);
qs_speed_course_res.setText("2. 对课程进度快/慢/适中的感受:\n\t\t\t"+qs_speed_course);
qs_course_reverse_res.setText("3. 是否希望多增加课堂翻转环节:\n\t\t\t"+qs_course_reverse);
qs_most_interest_res.setText("4. 课程中最感兴趣的部分:\n\t\t\t"+qs_most_interest);
qs_suggest_res.setText("5. 对讲课方式的建议:\n\t\t\t"+suggestion);
}
}
```
# 作业3-ListView控件

## 效果

## 说明
主要就是想呈现一个人物列表效果
定义了两个布局文件 主布局和一个listview布局 总体使用线性布局 即LinearLayout
主布局里包含listview

listview布局里面主要包含ImageView和Textview两种控件

定义了一个Person对象 数据直接是用实例化对象的方式

自定义了ListAdapter适配器

继承了ArrayAdapter

并重写了getView方法

ViewHolder里存放的是对应控件

# 作业4-页面跳转及数据传递

## 效果
主界面

注册界面

填写数据

自动填充

## 说明
OnCreate中设置监听器 监听注册账号对应的TextView 重写onClick方法用Intent实现跳转

同样 监听提交按钮 重写onClick方法 用Intent传递数据 setResult方法用于数据回传 最后调用finish来关闭activity

在MainActivity中重写onActivityResult方法
