我拼命寻找解决方案,我知道其中有一个解决方案很简单,但对于我的生活,我无法弄明白。我正在使用选项来填充列表视图以选择多个内容。我将检查的项目保存在我的数据库中。我遇到问题的地方是在不同的时间重新填充列表视图,显示所有项目并标记以前选择的项目。任何帮助都会很棒,谢谢。
public class SelectIndustries extends Activity {
ListView mIndustryList;
Button mSaveButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.industry_list);
mIndustryList = (ListView) findViewById(R.id.listView1);
mSaveButton = (Button) findViewById(R.id.saveIndustries);
String[] industries = getApplicationContext().getResources().getStringArray(R.array.industries);
final ArrayAdapter<String> industryArray = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, industries);
mIndustryList.setAdapter(industryArray);
mIndustryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mSaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SparseBooleanArray checked = mIndustryList.getCheckedItemPositions();
for (int i = 0; i < mIndustryList.getAdapter().getCount(); i++) {
if (checked.get(i)) {
String ind = industryArray.getItem(i);
InterestedIndustries t = new InterestedIndustries();
t.setACL(new ParseACL(ParseUser.getCurrentUser()));
t.put("user", ParseUser.getCurrentUser());
t.setUser(ParseUser.getCurrentUser());
t.setIndustry(ind);
t.setIndustryPosition(i);
t.saveInBackground();
}
}
Intent goToMain = new Intent(SelectIndustries.this, MainActivity.class);
startActivity(goToMain);
}
});
}