我有一个Android应用程序,包含一个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
}
}
任何人都可以看到我要去哪里吗?
麻烦,这只是我的一个错字...抱歉的混乱 –
嘿pippa,它很酷,没有biggy。 – petey
你可以发布你的createNewDeviceList()吗?它的机会是它不会向你的列表中添加任何新东西,并在原始中创建具有相同元素和顺序的新列表 – petey