java list加入listview_java – 具有ArrayList和ListView的Android Array Adapter在更改阵列列表时不会更新...

我有一个包含ListView的屏幕的

Android应用程序,我正在使用它来显示设备列表.这些设备被保存在一个阵列中.

我试图使用ArrayAdapter在列表中的屏幕上显示数组中的内容.

当我第一次加载SetupActivity类时,它可以工作,但是在addDevice()方法中有一个新的设备添加,这意味着更新保存设备的阵列.

我正在使用notifyDataSetChanged(),它应该更新列表,但似乎不起作用.

public class SetupActivity extends Activity

{

private ArrayList deviceList;

private ArrayAdapter 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();

deviceList = populateDeviceList(); //Get all the devices into the list

arrayAdapter = new ArrayAdapter(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

}

}

任何人都可以看到我出错的地方吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值