2

Every time enter the main activity, The code below will be executed and works fine(that means indexStatus.setText(msg.obj.toString()); alway shows the latest msg).

But if I press back button to switch out, and then switch in the same screen(The reBuildIndex will run again), the Log.d(TAG, msg.obj.toString()); works fine, print out latest msg, but indexStatus.setText doesn't work, the latest msg does not display as I expected.

What's going on here ? Any suggestion ?

void rebuildIndex(boolean reCreate) {
    final TextView indexStatus = (TextView) this.findViewById(R.id.index_status);
    indexStatus.setVisibility(View.INVISIBLE);
    indexStatus.setText(R.string.rebuild_index_progress_title);

    final Handler statusHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
      @Override
      public boolean handleMessage(Message msg) {
        if (msg.obj == null) {
          indexStatus.setVisibility(View.GONE);
        } else if (msg.obj.equals("show")) { // TODO quick demo, shouldn't use literal text.
          indexStatus.setVisibility(View.VISIBLE);
        } else {
          Log.d(TAG, msg.obj.toString());
          if (indexStatus.getVisibility() != View.VISIBLE) {
            indexStatus.setVisibility(View.VISIBLE);
          }
          indexStatus.setText(msg.obj.toString());
          indexStatus.invalidate();
        }
        return false;
      }
    });

    Indexer.rebuildIndexIfNecessary(statusHandler, reCreate);
  }

UPDATE:

I've added a indexStatus.invalidate(); after setText in the third condition, doesn't work either.

UPDATE: Wrong msg at original post, I said press home, but actually its back to switch out. home button switch out/in works fine.

UPDATE: Tried to place the handler as a global variable, but didn't work. Now I disabled back event.

WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138

1 Answers1

0

If the TextView needs to be always set visible in this part of the code:

if (indexStatus.getVisibility() != View.VISIBLE) {
    indexStatus.setVisibility(View.VISIBLE);
}

then remove the if part.

JD Hernandez
  • 1,785
  • 1
  • 20
  • 29