Mahdi Nouri
Mahdi Nouri

Reputation: 1389

how to get the value of edittext

i have a feedback activity and it has an EditText and a button :

<?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>

so user write his feedback and when he clicked on SEND button it should send to Parse host with this code:

            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();

and problem is here when users sends his feedback a null text will be send to Parse host

also i have tried this one:

            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();

but same as the first one

and then i have tried SharedPreferences and saving the value to SP and send SP value to Parse but its null :|

this is the feedback dialog:

 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();
}

anyone knows how i should fix this?

Upvotes: 0

Views: 58

Answers (1)

piotrek1543
piotrek1543

Reputation: 19351

EDIT: I've already changed a bit your code:

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();
}

If you're using SharedPreferences you need after putting variable, also commit it like in code above. I don't know what is doing your saveInBackground() method, but i think that adding .commit() after every argument should also work.

Please check it and let me know if it won't work

Upvotes: 1

Related Questions