New Value EditText not being displayed , no errors whatsoever

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



New Value EditText not being displayed , no errors whatsoever



EDIT : By the way , if i hard code edt4.setText("any text") IN THE SCOPE , it shows the value



EDIT2: tried rebuilding/cleaning project , could this be a bug in settext method, it looks like im doing it right . When i look at other code with settext



EDIT3: startactivityforresult might be my answer ? , i openend another question related to what i wanna try out , i still havent found another solution , stuck with this for a week now : (
this is the link to my question Can i use startActivityForResult , with one activity?



EDIT4 : now trying it with making views visible and invisible



I have read every single article about anything related on stackoverflow , dreamincode etc, and i cant find anybody that knows the answer for my problem.



I have a qr scanner and after a successful scan the result needs to be put in a EDIT TEXT field with name editText4 , my code throws no errors but it is NOT displaying any value .



I've posted on different forums but to no avail (https://www.dreamincode.net/forums/topic/412000-settext-is-not-showing-set-value-in-edittext-in-gui/page__st__15__gopid__2372214&#entry2372214)
, as you can see the commented code . That's pretty much also what I've tried , I think I somehow got to get my handle result method inside of the scope.



NOTE : Log.v outputs the result very well , but when i try anything else with the result it just don't works or being displayed



ps: I m beginner at java



Thanks for your help



here's my mainactivity


` public class MainActivity extends Activity implements
ZXingScannerView.ResultHandler {

Button sendButton;
EditText edt4;
EditText edt2;
private ZXingScannerView mScannerView;




@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


edt4 = findViewById(R.id.editText4);

mScannerView = findViewById(xmlScannerView);
mScannerView.setFormats(ZXingScannerView.ALL_FORMATS);
mScannerView.setResultHandler(this);
mScannerView.startCamera();







EditText delete2;
Button button3;

button3 = findViewById(R.id.button3);
delete2 = findViewById(R.id.editText2);

final EditText finalEdittext = delete2;
button3.setOnClickListener(new View.OnClickListener()

@Override
public void onClick(View v)
//Clear EditText
finalEdittext.getText().clear();


);

EditText delete4;
Button button4;

delete4 = findViewById(editText4);
button4 = findViewById(R.id.button4);

final EditText finalEdittext1 = delete4;
button4.setOnClickListener(new View.OnClickListener()

@Override
public void onClick(View v)
//Clear EditText
finalEdittext1.getText().clear();


);





@Override
public void onPause()
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause



public void onClick(View v)

RelativeLayout someid = findViewById(R.id.someId);
mScannerView.setVisibility(View.VISIBLE);
someid.setVisibility(View.INVISIBLE);



// EditText edt4;

@Override
public void handleResult(final Result result)
//handle result

Log.v("handleResult", result.getText());


edt4 = findViewById(editText4);
edt4.setText(result.getText());
//edt4.setText(String.valueOf(result.getText()));

// edt4.setText(new

StringBuilder().append("Resultaat:").append(result.getText()).toString());





`



this is xml :


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:background="@mipmap/ic_launcher_foreground">


android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">

<me.dm7.barcodescanner.zxing.ZXingScannerView

android:id="@+id/xmlScannerView"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_width="match_parent" />
<RelativeLayout

android:id="@+id/someId"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/editText4"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginTop="67dp"
android:ems="10"
android:hint="@string/scan_locatie"
android:inputType="text"

android:text=""
tools:backgroundTint="@android:color/holo_red_light" />


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText4"
android:layout_centerHorizontal="true"
android:background="@android:color/holo_red_light"
android:onClick="onClick"
android:text="@string/scan_qr"
tools:text="scan qr code" />

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="61dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="197dp"
android:ems="10"
android:hint="@string/scan_order"

android:inputType=""
android:visibility="visible"
tools:backgroundTint="@android:color/holo_red_light" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:background="@android:color/holo_red_light"
android:onClick="onClick"
android:text="@string/scan_qr"
tools:text="scan qr code" />

<Button
android:id="@+id/sendButton"
android:layout_width="157dp"
android:layout_height="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="72dp"
android:background="@android:color/holo_red_light"
android:text="@string/button"
tools:text="Versturen.." />


<Button
android:id="@+id/button3"
android:layout_width="40dp"
android:layout_height="38dp"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignParentEnd="true"
android:background="@android:drawable/ic_delete" />

<Button
android:id="@+id/button4"
android:layout_width="39dp"
android:layout_height="37dp"
android:layout_alignBaseline="@+id/editText4"
android:layout_alignParentEnd="true"
android:background="@android:drawable/ic_delete" />

</RelativeLayout>





EDIT:5 also changed XML , and main , still not working :(





Does result.getText() contain a value?
– Giovanni Terlingen
Aug 8 at 9:20


result.getText()





in log.v it does
– Maarten Vaartjes
Aug 8 at 9:22





(1) Is there any reason that you declared EditText edt4; right before handleResult() and not before onCreate()? (2) Is there a possibility there exists in your project another view with id editText4? (3) Why do you set the text of edt4 after you show the dialog?
– user8959091
Aug 8 at 9:53


EditText edt4;


handleResult()


onCreate()


editText4


edt4





(1) i was trying some things , (2) i've got a delete button on edittext 4
– Maarten Vaartjes
Aug 8 at 9:58





dialog isnt neccesary it was just for testing
– Maarten Vaartjes
Aug 8 at 13:41




3 Answers
3



I think result.getText() is a String anyway, so you could change the following line:


result.getText()


String


edt4.setText(String.valueOf(result.getText()));



To:


edt4.setText(result.getText());



After that you call updateScannerData, which is also writing to the EditText once again, but from the UI-Thread. I would recommend to remove the UI-Thread code as well since I assume the code runs on that Thread anyway.


updateScannerData


EditText


UI-Thread


UI-Thread


Thread





i was just one of the inmiddels millions of things i triedt
– Maarten Vaartjes
Aug 8 at 9:27






Try to check if only using this line works, try not to call updateScannerData to make sure result.getText() gets set.
– Giovanni Terlingen
Aug 8 at 9:28


updateScannerData


result.getText()





check mu update
– Maarten Vaartjes
Aug 8 at 9:29





okay , but im sure that it doesnt , i tried that
– Maarten Vaartjes
Aug 8 at 9:29





Try to run it, I can see that your current code will not compile at all.
– Giovanni Terlingen
Aug 8 at 9:31



try removing recreate();


recreate();



you are recreating the activity after setting the value, so the previous value is lost





the recreate is there to resume my activity , because somehow after a scan the scanner view gets frozen and can't return. Its weird but with recreate it's gone and it work good
– Maarten Vaartjes
Aug 6 at 10:29





startActivity(new Intent(this,MainActivity.class)); this.finish(); would this be good practice , instead of recreate ? EDIT: it does exactly the same only the transition seems smoother
– Maarten Vaartjes
Aug 6 at 11:07




You can either use


edt4.clear();



or


edt4.setText("");





see my edit , it works with hardcoded strings IF it's after setcontentview in the scope
– Maarten Vaartjes
Aug 6 at 10:32






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS