2Answers
  • 6
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Android: TextView not updating

I got one EditText and one TextView, and I want to update my TextView in each Iteration (ConsoleWindow is running in a loop; it gets called from a handler and thus is running on the UIthread).

The Problem is that my TextView only gets updated in the first round, and then it keeps the first entry for the rest of the runtime (although the dataString is a different one in each round):

private void ConsoleWindow(String dataString) {

    LinearLayout layout = new LinearLayout(getApplicationContext());

    if (first2) { //first2 is true when application is launched
        // ONLY SET LAYOUT AND EDITTEXT IN FIRST RUN TO SAVE CAPACITY

        // LINEAR LAYOUT
        setContentView(layout);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setBackgroundColor(Color.parseColor("#000000")); // black

        // EDITTEXT
        EditText et = new EditText(getApplicationContext());
        et.setHint("Enter Command");
        layout.addView(et);
        first2 = false;
    }


    // TEXTVIEW
    TextView tv = new TextView(getApplicationContext());
    tv.setText(dataString); // KEEPS THE SAME UNTIL THE 1ST ROUND
    layout.addView(tv);
}

I already tried tv.invalidate() and tv.postInvalidate(), but that didn't have an effect. Could someone help me please?

Put tv a global variable.

 private TextView tv; 

After this, In your "onCreate()" method:

tv = new TextView(getApplicationContext());

And then:

private void ConsoleWindow(String dataString) {

    LinearLayout layout = new LinearLayout(getApplicationContext());

    if (first2) { //first2 is true when application is launched
        // ONLY SET LAYOUT AND EDITTEXT IN FIRST RUN TO SAVE CAPACITY

        // LINEAR LAYOUT
        setContentView(layout);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setBackgroundColor(Color.parseColor("#000000")); // black

        // EDITTEXT
        EditText et = new EditText(getApplicationContext());
        et.setHint("Enter Command");
        layout.addView(et);
        first2 = false;
    }


    // TEXTVIEW
    tv.setText(dataString); // KEEPS THE SAME UNTIL THE 1ST ROUND
    layout.addView(tv);
}

Please verify too, if dataString has some text, with something like this

Log.d(TAG , "dataString: " + dataString + "with first time? " + first2.toString());

Try to pass to the setContentView(layout); outside the if statement.Because I can't understand well Why you need this.

LinearLayout layout = new LinearLayout(getApplicationContext());
setContentView(layout);
  • 1
Reply Report

When first2 is false, you are simply creating a new LinearLayout layout and then without inflating the layout, you are directly adding TextView tv to layout. That's why _Textvie_w is not visible.

private void ConsoleWindow(String dataString) {
    LinearLayout layout;
    TextView tv;
    EditText et;

    if (first2) {
        layout = new LinearLayout(getApplicationContext());

        setContentView(layout);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setBackgroundColor(Color.parseColor("#000000"));

        // EDITTEXT
        et = new EditText(getApplicationContext());
        et.setHint("Enter Command");
        layout.addView(et);

        tv = new TextView(getApplicationContext());
        layout.addView(tv);

        first2 = false;
    }
    if(tv != null) {
        tv.setText(dataString);
    }
}
  • 1
Reply Report