Note that there are some explanatory texts on larger screens.

plurals
  1. POScreen refusing to refresh after action
    text
    copied!<p>I am new to java and currently working on a project. I am trying to get familiar with the bluetooth. So far, i have been able to turn on and off bluetooth from within the app. The problem i have is that the screen does not refresh after an action has been carried out. For example, when i turn on the bluetooth, it comes on, but the text in the textview doesn't update until i flip the phone over. Same for when i disconnect. Here is my code</p> <pre><code>package com.example.bluetooth; import android.os.Bundle; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity { BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); Button button; TextView update; CharSequence enabled = "Bluetooth Enabled"; CharSequence disabled = "Bluetooth disabled"; CharSequence connect = "Connect"; CharSequence disconnect = "Disconnect"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setUp(); action(); } private void action() { if (button.getText() == connect) { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btAdapter.enable(); } }); } if (button.getText() == disconnect) { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { btAdapter.disable(); } }); } } private void setUp() { button = (Button) findViewById(R.id.button1); update = (TextView) findViewById(R.id.textView1); button = (Button) findViewById(R.id.button1); if (btAdapter.isEnabled()) { update.setText("Bluetooth is enabled"); button.setText(disconnect); } else { update.setText("Bluetooth is disabled"); button.setText(connect); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>Any help at all would be appreciated. Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload