I am using a custom List adapter to display a list of all contacts, and the user will then select contacts by clicking a checkbox. What is a good method of saving the selected contacts to preferences, so that I may test against them elsewhere? I was thinking of using SharedPreferences, but so far I have been unable to find a way to save an array to SharedPrefs. I could go the sqlite route, but that seems a bit excessive considering they are already contained in a db, and why couldn t I just reference them there. Just not sure how to even begin to do that... Also, I was thinking of calling this method onDestroy, though that could have some issues as well, so a recommendation on that could help as well. Here is some code (let me know if you need more,,,there s always more) thanks for your supreme knowledge.
ListItemLayout.xml:
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/text1"
android:includeFontPadding="false"
android:paddingBottom="4dip"
android:textSize="15sp"
android:textStyle="normal" />
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:focusable="false"
/>
</RelativeLayout>
</TwoLineListItem>
联系人 活动(为了简练而重订的一些法典):
public class ContactPicker extends ListActivity implements Runnable{
private List<Contact> contacts = null;
private Contact con;
private ContactArrayAdapter cAdapter;
private ProgressDialog prog = null;
private Context thisContext = this;
private CheckBox c1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prog = ProgressDialog.show(this, "Contact List", "Getting Contacts", true, false);
Thread thread = new Thread(this);
thread.start();
final CheckBox c1 = (CheckBox)findViewById(R.id.checkbox);
}
public void run() {...
}
private List<Contact> fillContactsList() {...
}
private Handler handler = new Handler() {...
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
TextView label = ((TwoLineListItem) v).getText2();
String phoneNumber = label.getText().toString();
}
}