添加捐款功能

my
Administrator 5 years ago
parent 282a28978a
commit 2fabb72173

@ -11,7 +11,8 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".BrowseRecordActivity"></activity> <activity android:name=".DonateActivity"></activity>
<activity android:name=".BrowseRecordActivity" />
<activity android:name=".NewsContentActivity" /> <activity android:name=".NewsContentActivity" />
<activity android:name=".RegiteActivity" /> <activity android:name=".RegiteActivity" />
<activity android:name=".SignInActivity"> <activity android:name=".SignInActivity">

@ -0,0 +1,155 @@
package hunnu.sj.raise_money;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DonateActivity extends AppCompatActivity {
Handler mHandler = new Handler(){//用于处理子线程传回的消息对主线的UI进行修改
int flag = -1;
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
String txt;
switch (msg.what){
case 1:
flag = 1;
txt = (String) msg.obj;
number.setError(txt);
break;
case 2:
flag= 2;
txt = (String) msg.obj;
money.setError(txt);
case 3:
flag=3;
txt = (String) msg.obj;
name.setError(txt);
}
}
};
EditText name;
EditText number;
EditText money;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_donate);
// Button commit = (Button) findViewById(R.id.commit);
// commit.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent intent;
// intent = new Intent(MainActivity.this,aActivity.class);
// startActivity(intent);
// }
// });
}
public void onToMain(View view){
Intent intent = new Intent(DonateActivity.this, MainActivity.class);
startActivity(intent);
// MessageCommit();
}
public void onClick(View view){
name=findViewById(R.id.Name);
number=findViewById(R.id.TeleNumber);
money=findViewById(R.id.Money);
new CommitThread().start();
}
// private void MessageCommit(){
// if(judge()){
// startActivity(intent);
// }
//
// }
// private boolean judge(){
//
// }
private int judgenum(String num){
if(num.length()!=11) return 1;
Pattern p = null;
Matcher m = null;
boolean b = false;
p = Pattern.compile("^[1][3,5,8][0-9]{9}$"); // 验证手机号
m = p.matcher(num);
b = m.matches();
if(!b) return 2;
return 3;
}
private int judgemon(String mon){
String reg_money = "\\d+(\\.\\d{1,2})?";// 金额正则,可以没有小数,小数最多不超过两位
Pattern pattern = Pattern.compile(reg_money);
Matcher matcher = pattern.matcher(mon);
boolean ismatch = matcher.matches();
if(ismatch) return 1;
return 0;
}
private int judgenam(String nam){
String regEx = "[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(nam);
boolean isMatch = matcher.matches();
if (isMatch) return 1;
return 0;
}
class CommitThread extends Thread{
@Override
public void run() {
int flag = -1;//先设置flag为-1
int flag1=-1;
int flag11=-1;
String mon = money.getText().toString();
String num = number.getText().toString();
String nam=name.getText().toString();
flag = judgenum(num);//用login函数来判断用户输入的用户名与密码是否正确
flag1=judgemon(mon);
flag11=judgenam(nam);
Message message = mHandler.obtainMessage();
if(flag==1){
message.what = 1;
message.obj = "电话号码位数不对";
mHandler.sendMessage(message);
}
else if(flag==2){
message.what = 1;
message.obj = "请输入正确的电话号码";
mHandler.sendMessage(message);
}
else if(flag1==0){
message.what = 2;
message.obj = "金额输入不对";
mHandler.sendMessage(message);
}else if(flag11==0){
message.what = 3;
message.obj = "姓名输入不对";
mHandler.sendMessage(message);
}
else{
Looper.prepare();
Toast toast=Toast.makeText(DonateActivity.this, "提交成功",Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 100, 100);
toast.show();
Looper.loop();
finish();
}
}
}
}

@ -4,7 +4,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.view.Window; import android.view.Window;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -26,7 +28,19 @@ public class NewsContentActivity extends AppCompatActivity{
NewsContentFragment newsContentFragment = (NewsContentFragment) NewsContentFragment newsContentFragment = (NewsContentFragment)
getFragmentManager().findFragmentById(R.id.news_content_fragment); getFragmentManager().findFragmentById(R.id.news_content_fragment);
newsContentFragment.refresh(newsTitle, newsContent); // 刷新NewsContentFragment界面 newsContentFragment.refresh(newsTitle, newsContent); // 刷新NewsContentFragment界面
onToDonate();
} }
public void onToDonate( ){
Button button1 = (Button) findViewById(R.id.button);//id后面为上方button的id
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent1 = new Intent();
intent1.setClass(NewsContentActivity.this, DonateActivity.class);//this前面为当前activty名称class前面为要跳转到得activity名称
startActivity(intent1);
}
});
}
} }

@ -0,0 +1,97 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:id="@+id/name"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/colorAccent"
android:text="姓名" />
<EditText
android:id="@+id/Name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="请输入你的姓名"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/teleNumber"
android:layout_width="40dp"
android:layout_height="34dp"
android:layout_weight="1"
android:maxLength="11"
android:numeric="integer"
android:textColor="@color/colorAccent"
android:text="电话号码" />
<EditText
android:id="@+id/TeleNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="请输入你的电话号码"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/money"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/colorAccent"
android:text="输入捐款金额" />
<EditText
android:id="@+id/Money"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="请输入捐赠金额"
android:inputType="numberDecimal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="481dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp">
<Button
android:id="@+id/commit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:onClick="onToMain"
android:text="跳转首页"></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:onClick="onClick"
android:text="提交">
</Button>
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save