приложение продолжает зависать из-за чего-то с помощью функции setadapter
Моя конечная цель состоит в том, чтобы иметь программу, которая подключается к Bluetooth и отображает представление списка, в котором можно кликнуть по соединенным устройствам Bluetooth. Я работал над многими учебниками и форумами и не мог заставить его работать. Любая помощь в правильном направлении будет принята с благодарностью. Спасибо
// Мой основной код:
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ListFragment;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.recyclerview.extensions.ListAdapter;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
public static int Request_Bluetooth = 1;
int bt = 1;
public ArrayList<BluetoothDevice> btDevices = new ArrayList<>();
ListView newDevices;
TextView tvDeviceName;
BluetoothAdapter Bluetooth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
Bluetooth = BluetoothAdapter.getDefaultAdapter();
newDevices = (ListView) findViewById(R.id.newDevices);
tvDeviceName = (TextView) findViewById(R.id.tvDeviceName);
btDevices = new ArrayList<>();
if(Bluetooth == null){
new AlertDialog.Builder(this)
.setTitle("Bluetooth")
.setMessage("This device does not support Bluetooth")
.setPositiveButton("Main Menu",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.exit(0);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
if (!Bluetooth.isEnabled()){
Intent enable = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enable, Request_Bluetooth);
}
Intent discoverable = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverable.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,1000);
startActivity(discoverable);
Set<BluetoothDevice> pairedDevices = Bluetooth.getBondedDevices();
ArrayAdapter<String> s = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, R.id.newDevices);
for(BluetoothDevice bt : pairedDevices) {
s.add(bt.getName());
//Used to check that the devices are being captured
// tvDeviceName.append("\n Device:" + bt.getName() + ", " +bt);
}
newDevices.setAdapter(s);
}
}
Пожалуйста, помогите