在我们的android中我们的意见反馈界面的话就是设置我们的相关的方法
然后的话我们的意见反馈界面要用到的控件有:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/my_suggestion_submit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:counterEnabled="true"
app:counterMaxLength="150"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/my_suggestion_submit"
android:layout_width="match_parent"
android:layout_height="250dp"
android:gravity="start|top|left"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btn_suggestion_submit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="64dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="64dp"
android:text="提交"
app:layout_constraintEnd_toEndOf="@+id/my_suggestion_submit_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/my_suggestion_submit_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
然后的话在我们的这个位置的话就是设置我们的java类型的代码:
package com.example.model_okhttp_and_yingdao.ui.PeopleList;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.Toast;
import com.example.model_okhttp_and_yingdao.R;
import com.example.model_okhttp_and_yingdao.ui.People.CenterPeopleFragment;
import com.example.model_okhttp_and_yingdao.ui.https.HttpUtil;
import com.example.model_okhttp_and_yingdao.ui.https.MyApplication;
import com.example.model_okhttp_and_yingdao.ui.https.OkhttpCallBack;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import java.io.IOException;
import java.util.HashMap;
public class SuggessActivity extends AppCompatActivity {
private TextInputLayout mySuggestionSubmitLayout;
private TextInputEditText mySuggestionSubmit;
private Button btnSuggestionSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_suggess);
// todo 在我们的这个位置的话就是设置我们的已将反馈的界面
initView();
}
private void initView() {
mySuggestionSubmitLayout = (TextInputLayout) findViewById(R.id.my_suggestion_submit_layout);
mySuggestionSubmit = (TextInputEditText) findViewById(R.id.my_suggestion_submit);
btnSuggestionSubmit = (Button) findViewById(R.id.btn_suggestion_submit);
// 在我们的这个位置的话就是设置我们的相关的意见反馈的界面
mySuggestionSubmit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
// 在我们的这个位置的话就是判断我们输入的字体的输入的数量
if(editable.length() > 150){
editable.delete(149,editable.length()-1);
// 在我们的这个位置的话就是弹出一个我们的toast的弹窗然后的恶化自动的将我们的超出的部分进行删除
MyApplication.showToast("不能超出150字");
}
}
});
btnSuggestionSubmit.setOnClickListener(view -> {
// 在我们的这个位置的话就是设置我们的相关的方法然后的话囧事将我们的东西提交到我们的服务器
HashMap<String,Object> map = new HashMap<>(); // 这个的话就是我们的hashmap的列表
String s = mySuggestionSubmit.getText().toString();
if(TextUtils.isEmpty(s)){
// map.put("userId", CenterPeopleFragment.user.getUserId());
// map.put("content" , s);
//
// HttpUtil.getInstance().doPost("/userinfo/feedback", map, new OkhttpCallBack() {
// @Override
// public void successful(String successString) throws IOException {
// // 然后的话找我们的这个位置的话显示我们的就是toast
// MyApplication.showToast("意见提交成功");
// }
//
// @Override
// public void failuer(String errorString) {
// MyApplication.showToast("意见提交成功");
// }
// });
// todo 意见反馈为空请输入我们的内容
Toast.makeText(SuggessActivity.this,"意见不能为空请重新输入",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(SuggessActivity.this,"意见提交成功",Toast.LENGTH_LONG).show();
mySuggestionSubmit.setText("");
// 然后的话在我们的这个位置的话就是清空我们的输入框中的内容
finish();
}
});
}
}
然后的话就是我们的相关界面的展示: