Android case: icon name setting + user login interface, [interview summary]

<Button

android:layout_width=“160dp”

android:layout_height=“48dp”

android:id="@+id/btn_baby"

android:layout_gravity=“center”

android:background="@color/gold"

android:text="Buy GO Now!"

android:textColor="@color/violet"

android:textSize=“18sp”

android:onClick=“click”

android:textStyle=“bold”/>

<TableLayout

android:layout_marginTop=“10dp”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_gravity=“center”

android:layout_marginLeft=“20dp”

android:layout_marginRight=“5dp”>

<TableRow

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<TextView

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text="Intelligence:"

android:textColor="@color/darkorchid"

android:textSize=“18sp”/>

<ProgressBar

android:id="@+id/progressBar4"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_gravity=“center”

android:layout_weight=“2”/>

<TextView

android:id="@+id/tv_brain_progress"

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:layout_gravity=“center”

android:text=“0”

android:textColor="#000000"

android:textSize=“18sp”/>

<TableRow

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<TextView

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text="Quality:"

android:textColor="@color/darkorchid"

android:textSize=“18sp”/>

<ProgressBar

android:id="@+id/progressBar5"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_gravity=“center”

android:layout_weight=“2”/>

<TextView

android:id="@+id/tv_quality_progress"

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:layout_gravity=“center”

android:text=“0”

android:textColor="#000000"

android:textSize=“18sp”/>

<TableRow

android:layout_width=“match_parent”

android:layout_height=“wrap_content”>

<TextView

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text="Capabilities:"

android:textColor="@color/darkorchid"

android:textSize=“18sp”/>

<ProgressBar

android:id="@+id/progressBar6"

style="?android:attr/progressBarStyleHorizontal"

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_gravity=“center”

android:layout_weight=“2”/>

<TextView

android:id="@+id/tv_ability_progress"

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:layout_gravity=“center”

android:text=“0”

android:textColor="#000000"

android:textSize=“18sp”/>

<Button

android:layout_marginTop=“10dp”

android:layout_width=“160dp”

android:layout_height=“48dp”

android:id="@+id/btn_study"

android:layout_gravity=“center”

android:background="@color/gold"

android:text="Learn and grow GO!"

android:textColor="@color/violet"

android:textSize=“18sp”

android:onClick=“click2”

android:textStyle=“bold”/>

  • Correspondingly, create a new Activity and name it: Show_Message

  • Initialize the progress bar and text editing components, obtain the user login information in the intent to display, and set the maximum value and zero of the progress bar

  • Monitor the shopping button of the store and set the intent

  • Rewrite the onActivityResult() method to obtain the data brought back by jumping back from other Activities

  • After getting the data, update the property progress box, and customize the method updateProgress()

  • Extension: onActivityResult
  • Back to Contents

  • onActivityResult(int requestCode, int resultCode, Intent data)

The first parameter: This integer requestCode is used to compare and judge with the value of requestCode in startActivityForResult, so as to confirm which Activity the returned data is returned from.

The second parameter: This integer resultCode is returned by the child Activity through its setResult() method. Applicable to when multiple activities return data, to identify which activity returns the value.

The third parameter: an Intent object with the returned data. The data of the specified data type can be obtained through the data.getXxxExtra( ); method.

  • code show as below:

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.ProgressBar;

import android.widget.TextView;

public class Show_Message extends AppCompatActivity {

private TextView u_name;

private TextView u_password;

private ProgressBar mProgressBar1;

private ProgressBar mProgressBar2;

private ProgressBar mProgressBar3;

private TextView mLifeTV;

private TextView mAttackTV;

private TextView mSpeedTV;

private ProgressBar mProgressBar4;

private ProgressBar mProgressBar5;

private ProgressBar mProgressBar6;

private TextView mBrainTV;

private TextView mQualityTV;

private TextView mAbilityTV;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_show_message);

Intent intent = getIntent();

String name = intent.getStringExtra(“name”);

String password = intent.getStringExtra(“password”);

u_name = (TextView)findViewById(R.id.u_name);

u_password = (TextView)findViewById(R.id.u_password);

u_name.setText("User:"+name);

u_password.setText("password:"+password);

mLifeTV = (TextView)findViewById(R.id.tv_life_progress);

mAttackTV = (TextView)findViewById(R.id.tv_attack_progress);

mSpeedTV = (TextView)findViewById(R.id.tv_speed_progress);

mBrainTV = (TextView)findViewById(R.id.tv_brain_progress);

mQualityTV = (TextView)findViewById(R.id.tv_quality_progress);

mAbilityTV = (TextView)findViewById(R.id.tv_ability_progress);

initProgress();

}

private void initProgress(){

mProgressBar1 = (ProgressBar)findViewById(R.id.progressBar1);

mProgressBar2 = (ProgressBar)findViewById(R.id.progressBar2);

mProgressBar3 = (ProgressBar)findViewById(R.id.progressBar3);

mProgressBar1.setMax(1000);

mProgressBar2.setMax(1000);

mProgressBar3.setMax(1000);

mProgressBar4 = (ProgressBar)findViewById(R.id.progressBar4);

mProgressBar4.setMax(100);

mProgressBar5 = (ProgressBar)findViewById(R.id.progressBar5);

mProgressBar5.setMax(100);

mProgressBar6 = (ProgressBar)findViewById(R.id.progressBar6);

mProgressBar6.setMax(100);

}

public void click(View view){

Intent intent = new Intent(this,Shop_Device.class);

startActivityForResult(intent,1);

}

public void click2(View view){

Intent intent2 = new Intent(this,For_Study.class);

startActivityForResult(intent2,1);

}

@Override

protected void onActivityResult(int requestCode,int resultCode,Intent data){

super.onActivityResult(requestCode,resultCode,data);

if(data!=null){

if(requestCode==1){

if(resultCode==1){

ItemInfo info = (ItemInfo)data.getSerializableExtra(“equipment”);

updateProgress(info);

}else{

Subject study = (Subject)data.getSerializableExtra(“study”);

updateProgress2(study);

}

}

}

}

private void updateProgress2(Subject study){

int progress4 = mProgressBar4.getProgress();

mProgressBar4.setProgress(progress4+study.getBrain());

mBrainTV.setText(mProgressBar4.getProgress()+"");

int progress5 = mProgressBar5.getProgress();

mProgressBar5.setProgress(progress5+study.getQuality());

mQualityTV.setText(mProgressBar5.getProgress()+"");

int progress6 = mProgressBar6.getProgress();

mProgressBar6.setProgress(progress6+study.getAbility());

mAbilityTV.setText(mProgressBar6.getProgress()+"");

}

private void updateProgress(ItemInfo info){

int progress1 = mProgressBar1.getProgress();

int progress2 = mProgressBar2.getProgress();

int progress3 = mProgressBar3.getProgress();

mProgressBar1.setProgress(progress1+info.getLife());

mProgressBar2. setProgress(progress2+info. getAcctack());

mProgressBar3.setProgress(progress3+info.getSpeed());

mLifeTV.setText(mProgressBar1.getProgress()+"");

mAttackTV.setText(mProgressBar2.getProgress()+"");

mSpeedTV.setText(mProgressBar3.getProgress()+"");

}

}

  • The effect is as shown in the figure:

5. Equipment purchase

Back to Contents

  • Add an item class to the equipment to store various attributes of the equipment: ItemInfo

  • Attributes have name, attack attribute, life attribute, speed attribute, assign get and set methods, and serialize

  • code show as below:

import java.io.Serializable;

public class ItemInfo implements Serializable {

private String name;

private int acctack;

private int life;

private int speed;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAcctack() {

return acctack;

}

public void setAcctack(int acctack) {

this.acctack = acctack;

}

public int getLife() {

return life;

}

public void setLife(int life) {

this.life = life;

}

public int getSpeed() {

return speed;

}

public void setSpeed(int speed) {

this.speed = speed;

}

public ItemInfo(String name, int acctack, int life, int spped){

this.name = name;

this.acctack = acctack;

this.life = life;

this.speed = spped;

}

}

  • Create a new layout Layout named: activity_shop_device.xml

  • Contents include: equipment attribute interface display

  • code show as below:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background="@drawable/backgroung"

android:orientation=“vertical”>

<LinearLayout

android:id="@+id/rl"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/sword_icon" />

<TextView

android:id="@+id/tv_name"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="product name" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_life"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="life value"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_attack"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="Attack Power"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_speed"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="speed"

android:textSize=“13sp” />

<LinearLayout

android:id="@+id/bmw"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:layout_marginTop=“20dp”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/bmw_icon" />

<TextView

android:id="@+id/tv_name2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="product name" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_below="@+id/bmw"

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_life2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="life value"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_attack2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="Attack Power"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_speed2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="speed"

android:textSize=“13sp” />

<LinearLayout

android:id="@+id/girl"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:layout_marginTop=“20dp”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/girl_icon" />

<TextView

android:id="@+id/tv_name3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="product name" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_below="@+id/girl"

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_life3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="life value"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_attack3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="Attack Power"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_speed3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="speed"

android:textSize=“13sp” />

  • Correspondingly, create a new Activity and name it: Shop_Device

  • Initialize equipment properties and display them on the interface

  • Set the click listener event for each item's LinearLayout

  • Obtain the clicked equipment data, rewrite setResult(), store the data in the intent, and jump back to the original display interface

  • Extension: setResult
  • Back to Contents

  • setResult(int resultCode, Intent data)

Call this method on the destination interface of the intended jump to return the data that the Activity wants to return to the main Activity.

The first parameter: the resultCode will be returned to onActivityResult() when the Activity ends, generally it is RESULT_CANCELED, and the value of RESULT_OK is -1 by default.

The second parameter: an Intent object, the data returned to the main Activity. In the intent object carrying the data to be returned, use the putExtra( ) method.

  • code show as below:

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

public class Shop_Device extends AppCompatActivity implements View.OnClickListener {

private ItemInfo itemInfo;

private ItemInfo itemInfo2;

private ItemInfo itemInfo3;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_shop_device);

// Initialize equipment properties

itemInfo = new ItemInfo(“金剑”,100,20,20);

itemInfo2 = new ItemInfo("BMW",50,10,180);

itemInfo3 = new ItemInfo("little maid",20,50,30);

// set click listener

findViewById(R.id.rl).setOnClickListener(this);

// Get interface elements

TextView mLifeTV = (TextView)findViewById(R.id.tv_life);

TextView mNameTV = (TextView)findViewById(R.id.tv_name);

TextView mAttackTV = (TextView)findViewById(R.id.tv_attack);

TextView mSpeedTV = (TextView)findViewById(R.id.tv_speed);

// UI settings

mLLifeTV.setText("life value +"+itemInfo.getLife());

mNameTV.setText(itemInfo.getName()+" ");

mSpeedTV.setText("Agility+"+itemInfo.getSpeed());

mAttackTV.setText("Attack+"+itemInfo.getAcctack());

// set click listener

findViewById(R.id.bmw).setOnClickListener(this);

TextView mLifeTV2 = (TextView)findViewById(R.id.tv_life2);

TextView mNameTV2 = (TextView)findViewById(R.id.tv_name2);

TextView mAttackTV2 = (TextView)findViewById(R.id.tv_attack2);

TextView mSpeedTV2 = (TextView)findViewById(R.id.tv_speed2);

mLLifeTV2.setText("life value +"+itemInfo2.getLife());

mNameTV2.setText(itemInfo2.getName()+" ");

mSpeedTV2.setText("Agility+"+itemInfo2.getSpeed());

mAttackTV2.setText("Attack+"+itemInfo2.getAcctack());

// set click listener

findViewById(R.id.girl).setOnClickListener(this);

TextView mLifeTV3 = (TextView)findViewById(R.id.tv_life3);

TextView mNameTV3 = (TextView)findViewById(R.id.tv_name3);

TextView mAttackTV3 = (TextView)findViewById(R.id.tv_attack3);

TextView mSpeedTV3 = (TextView)findViewById(R.id.tv_speed3);

mLLifeTV3.setText("Life +"+itemInfo3.getLife());

mNameTV3.setText(itemInfo3.getName()+" ");

mSpeedTV3.setText("Agility+"+itemInfo3.getSpeed());

mAttackTV3.setText("Attack+"+itemInfo3.getAcctack());

}

@Override

public void onClick(View v) {

// get intent

Intent intent = new Intent();

switch (v.getId()){

case R.id.rl:

// Store the serialized equipment object

intent.putExtra(“equipment”,itemInfo);

// return result code and intent

setResult(1,intent);

// close the interface

finish();

// exit selection

break;

case R.id.bmw:

// Store the serialized equipment object

intent.putExtra(“equipment”,itemInfo2);

// return result code and intent

setResult(1,intent);

// close the interface

finish();

// exit selection

break;

case R.id.girl:

// Store the serialized equipment object

intent.putExtra(“equipment”,itemInfo3);

// return result code and intent

setResult(1,intent);

// close the interface

finish();

// exit selection

break;

}

}

}

  • The effect is as shown in the figure:

  • After clicking to select the corresponding equipment, return to the user information display interface and update the attribute data

  • The effect is as shown in the figure:

  • Attach the following piece of code for learning skills:

  • 新建Layout:activity_for_study.xml

  • code show as below:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background="@drawable/backgroung"

android:orientation=“vertical”>

<LinearLayout

android:id="@+id/english"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/english_icon" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/st_name"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject name" />

<TextView

android:id="@+id/st_content"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject content" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_brain"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="intelligence"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_quality"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="quality"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_ability"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="capabilities"

android:textSize=“13sp” />

<LinearLayout

android:id="@+id/math"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:layout_marginTop=“20dp”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/math_icon" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/st_name2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject name" />

<TextView

android:id="@+id/st_content2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject content" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_below="@+id/bmw"

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_brain2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="intelligence"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_quality2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="quality"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_ability2"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="capabilities"

android:textSize=“13sp” />

<LinearLayout

android:id="@+id/china"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:layout_marginTop=“20dp”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/china_icon" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/st_name3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject name" />

<TextView

android:id="@+id/st_content3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject content" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_below="@+id/girl"

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_brain3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="intelligence"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_quality3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="quality"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_ability3"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="capabilities"

android:textSize=“13sp” />

<LinearLayout

android:id="@+id/politics"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background="#307f7f7f"

android:gravity=“center_vertical”

android:orientation=“horizontal”

android:layout_marginTop=“20dp”

android:padding=“5dp”>

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:background="@drawable/politics_icon" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/st_name4"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject name" />

<TextView

android:id="@+id/st_content4"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“20dp”

android:text="subject content" />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_below="@+id/girl"

android:layout_marginLeft=“40dp”

android:orientation=“vertical”>

<TextView

android:id="@+id/tv_brain4"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="intelligence"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_quality4"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="quality"

android:textSize=“13sp” />

<TextView

android:id="@+id/tv_ability4"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text="capabilities"

android:textSize=“13sp” />

  • Create a new subject class: Subject

  • code show as below:

import java.io.Serializable;

public class Subject implements Serializable {

private String name;

private String content;

private int brain;

private int quality;

private int ability;

public Subject(String name, String content, int brain, int quality, int ability) {

this.name = name;

this.content = content;

this.brain = brain;

this.quality = quality;

this.ability = ability;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getContent() {

return content;

}

public void setContent(String content) {

this.content = content;

}

public int getBrain() {

return brain;

}

public void setBrain(int brain) {

this.brain = brain;

}

public int getQuality() {

return quality;

}

public void setQuality(int quality) {

this.quality = quality;

}

public int getAbility() {

return ability;

}

public void setAbility(int ability) {

this.ability = ability;

}

}

  • New Activity: For_Study

  • code show as below:

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

public class For_Study extends AppCompatActivity implements View.OnClickListener{

private Subject study;

private Subject study2;

private Subject study3;

private Subject study4;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_for_study);

// Initialize subjects

study = new Subject("English", "Learn ten words a day", 2,3,5);

study2 = new Subject("Mathematics", "Learn a section every day", 5,2,5);

study3 = new Subject("Chinese", "Recite an ancient poem every day", 1,4,5);

study4 = new Subject("Politics", "Memorize a section every day", 3,3,5);

// set click listener

TextView mNameTV = (TextView)findViewById(R.id.st_name);

TextView mContentTV = (TextView)findViewById(R.id.st_content);

findViewById(R.id.english).setOnClickListener(this);

TextView mBrainTV = (TextView)findViewById(R.id.tv_brain);

TextView mQualityTV = (TextView)findViewById(R.id.tv_quality);

TextView mAbilityTV = (TextView)findViewById(R.id.tv_ability);

mNameTV.setText(study.getName()+" ");

mContentTV.setText(study.getContent());

mBrainTV.setText(“Intelligence+”+study.getBrain());

mQualityTV.setText("Quality+"+study.getQuality());

mAbilityTV.setText(“能 力+”+study.getAbility());

// set click listener

TextView mName2TV = (TextView)findViewById(R.id.st_name2);

TextView mContent2TV = (TextView)findViewById(R.id.st_content2);

findViewById(R.id.math).setOnClickListener(this);

TextView mBrain2TV = (TextView)findViewById(R.id.tv_brain2);

TextView mQuality2TV = (TextView)findViewById(R.id.tv_quality2);

TextView mAbility2TV = (TextView)findViewById(R.id.tv_ability2);

mName2TV.setText(study2.getName()+" ");

mContent2TV.setText(study2.getContent());

mBrain2TV.setText("intelligence+"+study2.getBrain());

mQuality2TV.setText("Quality+"+study2.getQuality());

mAbility2TV.setText("ability+"+study2.getAbility());

// set click listener

TextView mName3TV = (TextView)findViewById(R.id.st_name3);

TextView mContent3TV = (TextView)findViewById(R.id.st_content3);

findViewById(R.id.china).setOnClickListener(this);

TextView mBrain3TV = (TextView)findViewById(R.id.tv_brain3);

TextView mQuality3TV = (TextView)findViewById(R.id.tv_quality3);

TextView mAbility3TV = (TextView)findViewById(R.id.tv_ability3);

mName3TV.setText(study3.getName()+" ");

mContent3TV.setText(study3.getContent());

mBrain3TV.setText("intelligence+"+study3.getBrain());

mQuality3TV.setText("Quality+"+study3.getQuality());

mAbility3TV.setText("ability+"+study3.getAbility());

// set click listener

TextView mName4TV = (TextView)findViewById(R.id.st_name4);

TextView mContent4TV = (TextView)findViewById(R.id.st_content4);

end

Some students in the comments have questions about how to learn material design controls. My suggestion is to search on GitHub . There are many examples given by peers. These chestnuts are enough to get started.

A friend said that if you want to be serious, you need knowledge of NDK and JVM. For the first time, **NDK is not a mysterious thing. **You will know what is going on after following the official steps. It is nothing more than some code formats and native /JAVA memory interaction, the more advanced ones are native/JAVA thread interaction, thread interaction is indeed a bit painful, but it is good to avoid using it in general, besides, why do beginners care about NDK, according to my previous experience, only in It has been used in two projects of audio and video communication and an embedded signal processing (offline). The embedded signal processing is JAVA->NDK->.SO->MATLAB. My original MATLAB code is called, and most of the others are used. On the game, the general Internet company will have someone to give you the company's SO package.
As for the JVM, the part that should be mastered, believe me, you will master it, and those who should not master it will be done by those who specialize in the study of JVM.

In a word, usually write more and practice more. This is the most basic quality of a programmer. Try to squeeze time and read theoretical basic books. JVM is not the only virtual machine in the next 30 years, and JAVA may not be popular in the industry in the next 30 years. Other systems and languages ​​will also spring up, but your solid theory will allow you to quickly understand and learn a language or framework, and your usual writing will allow you to quickly and proficiently apply what you have learned to practice.
Beginners, in a word, practice more.

Due to the length of the article, copy the link to view the detailed article and get the link to the study notes: Go to my GitHub

Guess you like

Origin blog.csdn.net/m0_66264630/article/details/122964421