新值EditText未显示,没有任何错误 [英] New Value EditText not being displayed , no errors whatsoever

查看:56
本文介绍了新值EditText未显示,没有任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

顺便说一句,如果我在范围内将edt4.setText("any text")硬编码,它将显示值

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

尝试重建/清理项目,这可能是settext方法中的错误,看起来好像im做得对.当我用settext查看其他代码时

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

startactivityforresult可能是我的答案? ,我提出了与我想尝试的问题有关的另一个问题,我仍然没有找到另一个解决方案,坚持了一周了:( 这是我的问题的链接我可以将startActivityForResult与一项活动一起使用吗?

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

我已经阅读了每一篇有关stackoverflow,dreamincode等相关内容的文章,但找不到任何知道我问题答案的人.

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.

我有一个qr扫描仪,成功扫描后,需要将结果放入名称为editText4的EDIT TEXT字段中,我的代码未引发任何错误,但未显示任何值.

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.

注意:Log.v可以很好地输出结果,但是当我尝试执行其他任何操作时,结果将无法正常显示或显示

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:我是Java的初学者

ps: I m beginner at java

感谢您的帮助

这是我的主要活动

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




  }
`

这是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>

5还更改了XML,并且main仍然不起作用:(

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

推荐答案

我仍然认为result.getText()String,因此您可以更改以下行:

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

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

收件人:

edt4.setText(result.getText());

此后,您调用updateScannerData,它也会再次从UI-Thread写入EditText.我建议也删除UI-Thread代码,因为我假设代码仍然在Thread上运行.

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.

这篇关于新值EditText未显示,没有任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆