デバイスのリストを表示するために使用している ListView で構成される画面を備えた Android アプリがあります。これらのデバイスは配列に保持されます。
ArrayAdapter を使用して、画面上の配列にあるものをリストで表示しようとしています。
SetupActivityクラスを最初にロードすると機能しますが、 addDevice()メソッドに新しいデバイスを追加する機能があります。これは、デバイスを保持する配列が更新されることを意味します。
リストを更新するはずのnotifyDataSetChanged()を使用していますが、機能していないようです。
public class SetupActivity extends Activity
{
private ArrayList<Device> deviceList;
private ArrayAdapter<Device> arrayAdapter;
private ListView listView;
private DevicesAdapter devicesAdapter;
private Context context;
public void onCreate(Bundle savedInstanceState) //Method run when the activity is created
{
super.onCreate(savedInstanceState);
setContentView(R.layout.setup); //Set the layout
context = getApplicationContext(); //Get the screen
listView = (ListView)findViewById(R.id.listView);
deviceList = new ArrayList<Device>();
deviceList = populateDeviceList(); //Get all the devices into the list
arrayAdapter = new ArrayAdapter<Device>(this, android.R.layout.simple_list_item_1, deviceList);
listView.setAdapter(arrayAdapter);
}
protected void addDevice() //Add device Method (Simplified)
{
deviceList = createNewDeviceList(); //Add device to the list and returns an updated list
arrayAdapter.notifyDataSetChanged(); //Update the list
}
}
誰が私が間違っているのかを見ることができますか?