我正在尝试保存一个列表并将其存储在一个字符串中,然后在另一个活动中获取该字符串以显示所有这些项目。当我使用字符串people
时它很好,但是当我使用字符串finalp
时它不起作用。请告诉我我做错了什么?这是我的主要活动
public class MainActivity extends ListActivity {
String finalp;
String[] people = {
"Mike Strong",
"Jennifer Anniston",
"Tom Bennet",
"Leander Paes",
"Liam Nesson",
"George Clooney",
"Barack Obama",
"Steve Jobs",
"Larry Page",
"Sergey Brin",
"Steve Wozniak"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lstView = getListView();
lstView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, people));
}
public void onListItemClick(ListView parent, View v, int position, long id){
CheckedTextView item = (CheckedTextView) v;
if(item.isChecked()){
finalp.add(position);
}else if(!item.isChecked()){
finalp.remove(position);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_settings:
Intent myIntent = new Intent("com.vyprnoch.myapp1.CHECK");
startActivity(myIntent);
break;
}
return false;
}
这是我的 CheckedNames 活动
public class CheckedNames extends MainActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lstView = getListView();
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, finalp));
}
}