ListView
에 장치에 연결된 모든 Bluetooth 장치를 채우려고합니다. 나는 디버그를 통해 가서 ArrayAdapter
는 데이터를 수신하지만, 내 코드가ListList가 ArrayList 데이터에서 채워지지 않음
아래 Connect2.java
public class Connect2 extends ListFragment {
private LayoutInflater classInflater;
private ViewGroup classContainer;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.connect2,container,false);
final ListView listview = (ListView) v.findViewById(android.R.id.list);
BluetoothAdapter myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> pairedDevices = myBluetoothAdapter.getBondedDevices();
List<String> previousDevices = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices) {
previousDevices.add(bt.getName());
}
ArrayAdapter BTListAdapter = new ArrayAdapter<String>(getActivity(), R.layout.connect2, previousDevices);
listview.setAdapter(BTListAdapter);
return inflater.inflate(R.layout.connect2, container, false);
}
}
Connect2.xml을 표시되는 ListView
에 통과되지 않았다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:layout_weight="1"
android:id="@+id/connectNewBtn"
android:text="@string/newBT"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:text="@string/BTtoggle"
android:id="@+id/BTSwitch"
android:layout_weight="0"
android:layout_gravity="end"/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"/>
</LinearLayout>
오류가 있습니까? – Rohit5k2
제 대답을 참조하십시오. listview가로드 된 뷰를 반환하지 않습니다. 완전히 새로운 시각으로 돌아오고 있습니다. – Rohit5k2