2024/3/21
所花时间:3小时
代码行:160行
博客量:1篇
了解到的知识点:进行安卓第一次作业的倒数第二个页面的编写
package com.example.enroll;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class abilityanalysis extends AppCompatActivity {
private EditText mEditText_analysis_text;
private EditText mEditText_change_text;
private Button mButton_add_analysis;
/* private String str_analysis_text;
private String str_change_text;*/
private MySQLConnector mySQLConnector;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_abilityanalysis);
mEditText_analysis_text=findViewById(R.id.Edit_analysis_text);
mEditText_change_text=findViewById(R.id.Edit_change_text);
mButton_add_analysis=findViewById(R.id.btn_add_analysis);
mySQLConnector=new MySQLConnector();
mButton_add_analysis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertData2();
/* str_analysis_text=mEditText_analysis_text.getText().toString();
str_change_text=mEditText_change_text.getText().toString();*/
}
});
}
private void insertData2(){
String str_analysis_text=mEditText_analysis_text.getText().toString();
String str_change_text=mEditText_change_text.getText().toString();
try{
mySQLConnector.insertData2(str_analysis_text,str_change_text);
Toast.makeText(abilityanalysis.this, "添加成功", Toast.LENGTH_LONG).show();
}catch (Exception e){
Toast.makeText(abilityanalysis.this, "添加失败", Toast.LENGTH_LONG).show();
}
}
}
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class abilityanalysis extends AppCompatActivity {
private EditText mEditText_analysis_text;
private EditText mEditText_change_text;
private Button mButton_add_analysis;
/* private String str_analysis_text;
private String str_change_text;*/
private MySQLConnector mySQLConnector;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_abilityanalysis);
mEditText_analysis_text=findViewById(R.id.Edit_analysis_text);
mEditText_change_text=findViewById(R.id.Edit_change_text);
mButton_add_analysis=findViewById(R.id.btn_add_analysis);
mySQLConnector=new MySQLConnector();
mButton_add_analysis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertData2();
/* str_analysis_text=mEditText_analysis_text.getText().toString();
str_change_text=mEditText_change_text.getText().toString();*/
}
});
}
private void insertData2(){
String str_analysis_text=mEditText_analysis_text.getText().toString();
String str_change_text=mEditText_change_text.getText().toString();
try{
mySQLConnector.insertData2(str_analysis_text,str_change_text);
Toast.makeText(abilityanalysis.this, "添加成功", Toast.LENGTH_LONG).show();
}catch (Exception e){
Toast.makeText(abilityanalysis.this, "添加失败", Toast.LENGTH_LONG).show();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".abilityanalysis"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:gravity="center">
<TextView
android:layout_width="400dp"
android:layout_height="match_parent"
android:text="@string/ability_analysis"
android:textSize="40sp"
android:gravity="center"
android:textColor="#000000"
android:textStyle="bold">
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp">
<EditText
android:id="@+id/Edit_analysis_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:inputType="textMultiLine"
android:gravity="top|start"
android:hint="@string/analysis_text"
android:scrollbars="vertical"
android:scrollbarStyle="insideInset"
android:scrollbarDefaultDelayBeforeFade="1000"
android:fadeScrollbars="false"
android:scrollbarFadeDuration="0"
android:scrollbarSize="4dp"
android:textSize="25sp"
android:background="@null">
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp">
<EditText
android:id="@+id/Edit_change_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:inputType="textMultiLine"
android:gravity="top|start"
android:hint="@string/change_text"
android:scrollbars="vertical"
android:scrollbarStyle="insideInset"
android:scrollbarDefaultDelayBeforeFade="1000"
android:fadeScrollbars="false"
android:scrollbarFadeDuration="0"
android:scrollbarSize="4dp"
android:textSize="25sp"
android:background="@null">
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<Button
android:id="@+id/btn_add_analysis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_analysis"
tools:ignore="ButtonStyle">
</Button>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".abilityanalysis"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginTop="20dp"
android:gravity="center">
<TextView
android:layout_width="400dp"
android:layout_height="match_parent"
android:text="@string/ability_analysis"
android:textSize="40sp"
android:gravity="center"
android:textColor="#000000"
android:textStyle="bold">
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp">
<EditText
android:id="@+id/Edit_analysis_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:inputType="textMultiLine"
android:gravity="top|start"
android:hint="@string/analysis_text"
android:scrollbars="vertical"
android:scrollbarStyle="insideInset"
android:scrollbarDefaultDelayBeforeFade="1000"
android:fadeScrollbars="false"
android:scrollbarFadeDuration="0"
android:scrollbarSize="4dp"
android:textSize="25sp"
android:background="@null">
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp">
<EditText
android:id="@+id/Edit_change_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:inputType="textMultiLine"
android:gravity="top|start"
android:hint="@string/change_text"
android:scrollbars="vertical"
android:scrollbarStyle="insideInset"
android:scrollbarDefaultDelayBeforeFade="1000"
android:fadeScrollbars="false"
android:scrollbarFadeDuration="0"
android:scrollbarSize="4dp"
android:textSize="25sp"
android:background="@null">
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<Button
android:id="@+id/btn_add_analysis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_analysis"
tools:ignore="ButtonStyle">
</Button>
</LinearLayout>
</LinearLayout>