[英]Android, How do i Update the selected item in my listview from my database?
Here's my code so far, but the application crashes when I press the update button. 到目前为止,这是我的代码,但是当我按下更新按钮时,应用程序崩溃了。
I want to update a selected item in my list, I have already created the update activity that will allow me to load the values on my database but I can't figure out how to load the value of selected item in list. 我想更新列表中的选定项目,我已经创建了更新活动,该活动将允许我将值加载到数据库中,但是我不知道如何加载列表中选定项的值。
{
ArrayAdapter<String> ard=new ArrayAdapter<String> (this,android.R.layout.simple_list_item_single_choice,list);
lv.setAdapter(ard);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
btnupdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
SparseBooleanArray sba = lv.getCheckedItemPositions();
Intent intent = new Intent(HomeworkInfo.this, UpdateHomework.class);
startActivity(intent);
finish();
}
});
}
When an ArrayAdapter is constructed, it holds the reference for the List that was passed in. If you were to pass in a List that was a member of an Activity, and change that Activity member later, the ArrayAdapter is still holding a reference to the original List. 构造ArrayAdapter时,它保留传入的List的引用。如果要传入的是Activity成员的List,并且以后再更改该Activity成员,则ArrayAdapter仍然持有对List的引用。原始清单。 The Adapter does not know you changed the List in the Activity.
适配器不知道您更改了活动中的列表。
Your choices are: 您的选择是:
I hope this helps you .. Happy coding !! 希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.