XML代码:
以下是反馈表单的XML
文件的代码。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none"
android:paddingBottom="10dp"
tools:context="com.example.administrator.feedbackform.MainActivity">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/toolbar_layout">
</include>
<TextView
android:id="@+id/TextView_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Feedback Is Important For Us!"
android:layout_marginTop="20dp"
android:gravity="center"
android:layout_gravity="center"
android:textSize="10pt">
</TextView>
<EditText
android:id="@+id/EditText_Enter_your_name"
android:layout_height="wrap_content"
android:hint="Enter your name here"
android:inputType="textPersonName"
android:textColorHint="#00E676"
android:layout_marginTop="25dp"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_gravity="center">
</EditText>
<EditText
android:id="@+id/EditText_Enter_your_Email"
android:layout_height="wrap_content"
android:hint="Please enter your email here"
android:textColorHint="#00E676"
android:inputType="textEmailAddress"
android:layout_marginTop="8dp"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_gravity="center"
>
</EditText>
<EditText
android:id="@+id/EditText_FeedbackBody"
android:layout_height="wrap_content"
android:hint="@string/hint1"
android:inputType="textMultiLine"
android:layout_width="fill_parent"
android:gravity="top|left"
android:layout_marginTop="15dp"
android:layout_gravity="center"
android:textColorHint="#00E676"
android:scrollbars="vertical"
android:background="#FFFDE7"
>
</EditText>
<CheckBox
android:id="@+id/CheckBoxResponse"
android:layout_height="wrap_content"
android:text="Are you sure you want to submit? Check the box then!"
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
>
</CheckBox>
<Button
android:id="@+id/ButtonSendFeedback"
android:layout_height="40dp"
android:text="Submit"
android:layout_marginTop="25dp"
android:layout_gravity="center"
android:onClick="sendFeedback"
android:layout_width="100dp"
android:background="@color/colorPrimaryDark">
</Button>
</LinearLayout>
</ScrollView>
Java代码:
以下是反馈表单的java文件的代码。
package com.example.administrator.feedbackform;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
Button Submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=(Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final EditText nameField = (EditText) findViewById(R.id.EditText_Enter_your_name);
String name = nameField.getText().toString();
final EditText emailField = (EditText) findViewById(R.id.EditText_Enter_your_Email);
String email = emailField.getText().toString();
final EditText feedbackField = (EditText) findViewById(R.id.EditText_FeedbackBody);
String feedback = feedbackField.getText().toString();
final CheckBox responseCheckbox = (CheckBox) findViewById(R.id.CheckBoxResponse);
boolean bRequiresResponse = responseCheckbox.isChecked();
Submit=(Button)findViewById(R.id.ButtonSendFeedback);
Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"Thanks! Your Feedback is submitted.",Toast.LENGTH_LONG).show();
}
});
}
}
假设有一个Logout按钮,那么,请建议在用户退出应用程序之前如何显示反馈表单。如果你能回答确切的代码,我将不胜感激!
答案 0 :(得分:2)
@GuneetKaur,
1)您可以做的是当您按下注销按钮时,您可以调用另一个包含反馈屏幕的活动。
2)单击注销按钮时,可以显示“警告对话框”。
3)如果你想在用户单击后退按钮退出应用程序时想要相同,那么你可以覆盖onBackPress()方法并从中删除super.onBackPress(),然后你可以保持标志,如果用户单击后面然后你可以检查是否给出了反馈然后你可以将标志更改为true然后调用finish()方法或super.onBackPress()
4)警报对话框的情况相同。
添加一些参考代码
logout_button.setOnClickListener(
new OnClickListener(View view){
// Call your Dialog for feedback
OR
// Call your Feedback Activity
}
);
//Generally this below method is called in Activity from where the Application gets closed
@Override
public void onBackPressed() {
//Remove this super.onBackPressed();
// Call your Dialog for feedback
OR
// Call your Feedback Activity
}
答案 1 :(得分:1)
您可以做的是显示一个对话框。定义一个新的警告对话框。使用您对反馈表单的布局设置其视图。
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.your_custom_layout, null,false);
dialogBuilder.setView(dialogView);
EditText editText =(EditText)dialogView.findViewById(R.id.label_field);
像这样,您可以实例化所有布局项目(例如用户在填写所有帖子后将会点击的提交按钮)。
然后,单击您的注销按钮,您可以使用以下代码显示警告日期。
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
答案 2 :(得分:1)
要专门完成您的要求,您应该在代码中以编程方式设置onClickListener
。在该代码中(我假设您将其置于原始活动中),您将创建一个启动反馈表单的意图,然后在以下行中调用finish
方法。调用finish
将从后台堆栈中删除原始活动,以便当他们按下或finish
反馈表单时,应用程序应该关闭。
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
});
答案 3 :(得分:1)
单击“注销”时使用警告对话框
ViewDialog alert = new ViewDialog();
public class ViewDialog {
alert.showDialog(MainActivity.this, "GIVE FEADBACK");
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.updatedialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogUpdate = (Button) dialog.findViewById(R.id.update);
Button dialogcancel = (Button) dialog.findViewById(R.id.cancel);
Button dialogremindme = (Button) dialog.findViewById(R.id.remindeme);
TextView textView= (TextView) dialog.findViewById(R.id.machhint1);
TextView textView2= (TextView) dialog.findViewById(R.id.machhint2);
dialogcancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialogUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do code for for update fedabck
}
dialog.dismiss();
}
});
dialogremindme.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//if you dont want to send feadback
dialog.dismiss();
}
});
dialog.show();
}
}
PLEASE MAKE XML YOURSELF