Brauchen Sie Hilfe zu diesem Thema. Wenn der Benutzer seine Daten eingibt und in der Datenbank speichert, möchte ich, dass die Schaltfläche eine neue Aktivität öffnet, nachdem sie gespeichert wurde ... bis jetzt hat meine App die Daten einfach gespeichert und stoppt nur auf der activity_form.xml.need
Hilfe, wie man das Senden durchführt Taste öffnen neue Aktivität, nachdem es die Daten speichert würde sehr geschätzt werden, wenn mir jemand auf diese bitte helfen kann. TQ. HierWie Sie Daten in einer Datenbank speichern und neue Aktivitäten nach dem Speichern öffnen?
ist mein formActivity.java
:
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import android.view.View.OnClickListener;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FormActivity extends Activity implements View.OnClickListener, AdapterView.OnItemSelectedListener {
private static final String REGISTER_URL = "http://khaty-ismail0.rhcloud.com/phptutorial/submitData.php";
private static final String SPINNER_URL = "http://khaty-ismail0.rhcloud.com/phptutorial/spinner_data.php";
public static final String KEY_NAME= "Name";
public static final String KEY_AGE = "Age";
public static final String KEY_EMAIL = "Email";
public static String KEY_GENDER = "gender";
public static final String KEY_PHONE = "Phone";
public static final String KEY_DESCRIPTION = "Description";
public static final String KEY_TICKET = "ticket_id";
public static final String KEY_SOLUTION = "solution";
public static final String JSON_ARRAY = "result";
String gender ="";
private EditText name_eT;
private EditText age_eT;
private EditText email_eT;
private EditText phone_eT;
private EditText descr_eT;
private RadioGroup radioGroup;
private Button subm_btn;
private Spinner spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
name_eT = (EditText) findViewById(R.id.name_eT);
age_eT = (EditText) findViewById(R.id.age_eT);
email_eT= (EditText) findViewById(R.id.email_eT);
phone_eT= (EditText) findViewById(R.id.phone_eT);
descr_eT= (EditText) findViewById(R.id.descr_eT);
subm_btn = (Button) findViewById(R.id.subm_btn);
subm_btn.setOnClickListener(this);
spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(), spinner.getSelectedItem().toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
private void registerUser(){
final String Name = name_eT.getText().toString().trim();
final String Age = age_eT.getText().toString().trim();
final String Email = email_eT.getText().toString().trim();
final String Phone = phone_eT.getText().toString().trim();
final String Description = descr_eT.getText().toString().trim();
if(TextUtils.isEmpty(Name)) {
name_eT.setError("Please enter your name");
return;
}else if(TextUtils.isEmpty(Age)) {
age_eT.setError("Please enter your age");
return;
}else if(TextUtils.isEmpty(Phone)) {
phone_eT.setError("Please enter your phone");
return;
}else if(TextUtils.isEmpty(Email)) {
email_eT.setError("Please enter your email");
return;
}else if(TextUtils.isEmpty(Description)) {
descr_eT.setError("Please enter your issue");
return;
}
final RadioGroup radioGroup =(RadioGroup)findViewById(R.id.radioGroup);
final RadioButton male_rb=(RadioButton)findViewById(R.id.male_rb);
final RadioButton female_rb=(RadioButton)findViewById(R.id.female_rb);
if (radioGroup.getCheckedRadioButtonId()== male_rb.getId())
{
KEY_GENDER = "Male";
}
else if (radioGroup.getCheckedRadioButtonId()==female_rb.getId()){
KEY_GENDER = "Female";
}
StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(FormActivity.this,response,Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(FormActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put(KEY_NAME,Name);
params.put(KEY_AGE,Age);
params.put(KEY_GENDER,gender);
params.put(KEY_EMAIL, Email);
params.put(KEY_PHONE, Phone);
params.put(KEY_DESCRIPTION, Description);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
public void onCheckboxClicked(View V) {
boolean checked = ((RadioButton) V).isChecked();
switch (V.getId()) {
case R.id.male_rb:
if (checked)
break;
case R.id.female_rb:
if (checked)
break;
}
}
@Override
public void onClick(View v) {
if(v == subm_btn){
registerUser();
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
/*public void submitData(View view) {
Intent getResponse = new Intent(this,SubmitData.class);
final int result = 1;
startActivityForResult(getResponse, result);
}*/
}
Hier ist activity_form.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/buttonFont"
tools:context="com.example.khadijah.brucertv2.FormActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/User_info"
android:id="@+id/userInfo"
android:textSize="30sp"
android:textColor="@color/colorFont"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Name:"
android:id="@+id/name_tV"
android:textColor="@color/colorFont"
android:layout_marginTop="24dp"
android:layout_below="@+id/userInfo"
android:layout_alignLeft="@+id/userInfo"
android:layout_alignStart="@+id/userInfo" />
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Age:"
android:id="@+id/age_tV"
android:textColor="@color/colorFont"
android:layout_alignBottom="@+id/age_eT"
android:layout_alignLeft="@+id/name_tV"
android:layout_alignStart="@+id/name_tV" />
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Gender"
android:id="@+id/gender_tV"
android:textColor="@color/colorFont"
android:layout_below="@+id/age_tV"
android:layout_alignLeft="@+id/age_tV"
android:layout_alignStart="@+id/age_tV"
android:layout_marginTop="24dp" />
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Email:"
android:id="@+id/email_tV"
android:textColor="@color/colorFont"
android:layout_alignBottom="@+id/email_eT"
android:layout_alignLeft="@+id/name_tV"
android:layout_alignStart="@+id/name_tV" />
<TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="Phone"
android:id="@+id/phone_tV"
android:textColor="@color/colorFont"
android:layout_alignBottom="@+id/phone_eT"
android:layout_alignLeft="@+id/gender_tV"
android:layout_alignStart="@+id/gender_tV" />
<EditText
android:layout_width="200dp"
android:layout_height="30dp"
android:layout_marginBottom="5dp"
android:inputType="textPersonName"
android:hint="@string/hint_required"
android:textColorHint="@color/buttonFont"
android:background="@drawable/border_style"
android:ems="10"
android:id="@+id/name_eT"
android:textColor="@color/inputFont"
android:layout_alignBottom="@+id/name_tV"
android:layout_alignRight="@+id/userInfo"
android:layout_alignEnd="@+id/userInfo" />
<EditText
android:layout_width="200dp"
android:layout_height="30dp"
android:inputType="number"
android:ems="10"
android:hint="@string/hint_required"
android:textColorHint="@color/buttonFont"
android:background="@drawable/border_style"
android:id="@+id/age_eT"
android:textColor="@color/inputFont"
android:layout_below="@+id/name_tV"
android:layout_alignRight="@+id/userInfo"
android:layout_alignEnd="@+id/userInfo" />
<EditText
android:layout_width="200dp"
android:layout_height="30dp"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/email_eT"
android:hint="@string/hint_required"
android:textColorHint="@color/buttonFont"
android:textColor="@color/inputFont"
android:background="@drawable/border_style"
android:layout_below="@+id/phone_eT"
android:layout_alignLeft="@+id/age_eT"
android:layout_alignStart="@+id/age_eT" />
<EditText
android:layout_width="200dp"
android:layout_height="30dp"
android:inputType="phone"
android:ems="10"
android:id="@+id/phone_eT"
android:layout_marginBottom="5dp"
android:textColor="@color/inputFont"
android:hint="@string/hint_required"
android:textColorHint="@color/buttonFont"
android:background="@drawable/border_style"
android:layout_below="@+id/gender_tV"
android:layout_alignLeft="@+id/email_eT"
android:layout_alignStart="@+id/email_eT" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/incident_info"
android:id="@+id/incidentInfo"
android:textColor="@color/colorFont"
android:textStyle="bold"
android:textSize="30sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:prompt="@array/incident_type"
android:entries="@array/incident_type"
android:layout_below="@+id/incidentInfo"
android:layout_alignLeft="@+id/phone_eT"
android:layout_alignStart="@+id/phone_eT"
android:layout_alignRight="@+id/phone_eT"
android:layout_alignEnd="@+id/phone_eT"
android:spinnerMode="dropdown" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/incident_type_DD"
android:textColor="@color/colorFont"
android:id="@+id/incident_DD"
android:layout_below="@+id/incidentInfo"
android:layout_toLeftOf="@+id/spinner"
android:layout_toStartOf="@+id/spinner" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/description"
android:id="@+id/description_tV"
android:textColor="@color/colorFont"
android:layout_below="@+id/spinner"
android:layout_alignLeft="@+id/phone_tV"
android:layout_alignStart="@+id/phone_tV" />
<EditText
android:layout_width="300dp"
android:layout_height="80dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/descr_eT"
android:hint="@string/descr_hint"
android:textColorHint="@color/buttonFont"
android:gravity="top"
android:background="@drawable/border_style"
android:textColor="@color/inputFont"
android:layout_below="@+id/description_tV"
android:layout_alignLeft="@+id/description_tV"
android:layout_alignStart="@+id/description_tV" />
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="5dp"
android:text="SUBMIT"
android:onClick="submitData"
android:textStyle="bold"
android:textSize="35sp"
android:id="@+id/subm_btn"
android:background="@drawable/custom_btn"
android:textColor="@color/buttonFont"
android:layout_alignParentBottom="true"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignLeft="@+id/phone_eT"
android:layout_alignStart="@+id/phone_eT"
android:layout_below="@+id/age_eT"
android:layout_alignRight="@+id/descr_eT"
android:layout_alignEnd="@+id/descr_eT"
android:layout_above="@+id/phone_eT"
android:weightSum="1"
android:id="@+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="Male"
android:id="@+id/male_rb"
android:onClick="onCheckboxClicked"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:checked="false"
android:id="@+id/female_rb"
android:onClick="onCheckboxClicked"/>
</RadioGroup>
</RelativeLayout>
ich den Absenden-Button soll eine weitere Aktivität submit_data.xml
genannt speichern und zu öffnen:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/buttonFont"
android:padding="16dp"
tools:context="com.example.khadijah.brucertv2.SubmitData">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Thank You for reporting to BruCERT."
android:id="@+id/text1"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="You will be entertained within 24hours. Your information will be treated strictly confidential."
android:id="@+id/text2"
android:layout_below="@+id/text1"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Please retain the ticket number for quick follow up and to ensure effective response."
android:id="@+id/text3"
android:layout_below="@+id/text2"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp" />
</RelativeLayout>
Hier die submitData.java
:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
/**
* Created by Khadijah on 3/29/2016.
*/
public class SubmitData extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.submit_data);
}
public void submitData(View view) {
Intent getResponse = new Intent(this,SubmitData.class);
final int result = 1;
startActivityForResult(getResponse, result);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.khadijah.brucertv2">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/brucertlogotrans"
android:supportsRtl="true"
android:theme="@android:style/Theme.Holo.Light">
<activity
android:name=".splash"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="com.example.khadijah.brucertv2.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>-->
</activity>
<activity
android:name=".FormActivity"
android:label="Online Form">
<intent-filter>
<action android:name="com.example.khadijah.brucertv2.FormActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SubmitData"
android:label="Feedback">
<intent-filter>
<action android:name="com.example.khadijah.brucertv2.SubmitData" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Können Sie ein minimales Beispiel angeben, das das Problem zeigt? Versuchen Sie, nur Codebeispiele für die jeweilige Frage einzubeziehen. –
Es gibt keinen Fehler in der App. Wenn der Benutzer Daten senden, es in meiner Datenbank speichern. Was ich will ist, wenn der Benutzer "Senden" drücken, die Daten erfolgreich gespeichert dann öffnet es automatisch ein anderes Layout.so weit es nur gespeichert und stoppen Sie stattdessen im Formular-Layout statt wenn eine andere XML-Datei geöffnet wird. – user6181358
Ich habe nicht gesagt, dass es einen "Fehler" gab, aber es hat anscheinend ein Problem (weshalb Sie hier sind). Versuchen Sie, so viel Code wie möglich zu entfernen, bis Sie ein viel kleineres Beispiel haben, mit dem wir Ihnen helfen können. Niemand möchte alle über 500 Zeilen Ihres Codes lesen, aber wenn Sie es abschneiden - entfernen Sie alle unnötigen Dinge -, dann sehen wir uns Ihren Code eher an. (Versuchen Sie uns zu verkaufen, wenn Sie Ihre Frage lesen.) Und Sie könnten das Problem tatsächlich selbst entdecken! –