我有一个反馈活动,它有一个EditText和一个按钮:
<?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="230dp"
android:background="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:text="@string/bugtitle"
android:textSize="35sp"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:id="@+id/BUG_title"
android:fontFamily="sans-serif-thin"/>
<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@+id/BUG_title"
android:layout_marginTop="15dp"
android:layout_marginRight="30dp"
android:id="@+id/et_bug"
android:layout_marginLeft="30dp"
android:fontFamily="sans-serif-light"
android:hint="@string/bug_et"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:text="SEND"
android:fontFamily="sans-serif-light"
android:id="@+id/send_bug"/>
</RelativeLayout>
所以用户写下他的反馈,当他点击SEND按钮时,它应该使用以下代码发送给Parse主机:
et1 = (EditText)findViewById(R.id.et_bug);
ParseObject bugsend = new ParseObject("BUGS");
bugsend.put("BUG_REPORT", et1.getText().toString());
bugsend.put("OS", OS_VERSION);
bugsend.put("MODEL", PHONE_MODEL);
bugsend.saveInBackground();
问题出在这里,当用户发送他的反馈时,空文本将被发送到Parse主机
我也试过这个:
et1 = (EditText)findViewById(R.id.et_bug);
String BUG_SEND = et1.getText().toString();
ParseObject bugsend = new ParseObject("BUGS");
bugsend.put("BUG_REPORT", BUG_SEND);
bugsend.put("OS", OS_VERSION);
bugsend.put("MODEL", PHONE_MODEL);
bugsend.saveInBackground();
但与第一个相同
然后我尝试了SharedPreferences并将值保存到SP并将SP值发送到Parse但它的null:|
这是反馈对话框:
public void onBug(View view) {
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.bug_dialog);
Button dialogButton = (Button) dialog.findViewById(R.id.send_bug);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String PHONE_MODEL = android.os.Build.MODEL;
final String OS_VERSION = Build.VERSION.RELEASE;
et1 = (EditText)findViewById(R.id.et_bug);
String BUG_SEND = et1.getText().toString();
ParseObject bugsend = new ParseObject("BUGS");
bugsend.put("BUG_REPORT", BUG_SEND);
bugsend.put("OS", OS_VERSION);
bugsend.put("MODEL", PHONE_MODEL);
bugsend.saveInBackground();
Toast.makeText(getApplication(),"Thank You We Will Check This Report",Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
dialog.show();
}
有谁知道我应该如何解决这个问题?
答案 0 :(得分:1)
public void onBug(View view) {
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.bug_dialog);
Button dialogButton = (Button) dialog.findViewById(R.id.send_bug);
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseObject bugsend = new ParseObject("BUGS");
bugsend.put("BUG_REPORT", et1.getText().toString()).commit();
bugsend.put("OS", Build.VERSION.RELEASE;).commit();
bugsend.put("MODEL", android.os.Build.MODEL).commit();
bugsend.saveInBackground(); //THIS GUY
Toast.makeText(getApplication(),"Thank You We Will Check This Report",Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
dialog.show();
}
如果您在使用变量之后需要SharedPreferences
,那么也可以像上面的代码一样提交它。我不知道你的saveInBackground()方法在做什么,但我认为在每个参数之后添加.commit()
也应该有效。
请检查一下,如果它不能正常工作,请告诉我