所以我通过创建一个弹出列表活动解决了这个问题。
public class FeedChooserPopupActivity extends Activity {
ListView listView;
Cursor cursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feed_chooser);
initViews();
}
private void initViews(){
setupCursor();
setupListView();
setupButton();
}
private void setupButton() {
((Button)findViewById(R.id.feedOkbutton)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FeedChooserPopupActivity.this.finish();
}
});
}
private void setupCursor() {
cursor = getContentResolver().query(EntryProvider.WEBSITES_URI,null,null,null,EntryProvider.WEBSITES_SORT_ORDER);
}
private void setupListView() {
listView = (ListView)findViewById(R.id.feedListView);
listView.setAdapter(new FeedCursorAdapter(this,
cursor,
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER
));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (view != null) {
String websiteName = ((TextView)view.findViewById(R.id.feedTextView)).getText().toString();
CheckBox checkBox = (CheckBox)view.findViewById(R.id.feedCheckBox);
checkBox.setChecked(!checkBox.isChecked());
ContentValues cv = new ContentValues();
int enabled = 0;
if(checkBox.isChecked()){
enabled = 1;
}
cv.put(EntryData.KEY_WEBSITE_ENABLED, enabled);
String where = EntryData.KEY_WEBSITE_NAME+" = '"+websiteName+"'";
getContentResolver().update(EntryProvider.WEBSITES_URI,cv,where,null);
}
}
});
}
private class FeedCursorAdapter extends CursorAdapter {
public FeedCursorAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.feed_chooser_list_item,parent,false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
((TextView)view.findViewById(R.id.feedTextView)).setText(cursor.getString(EntryData.COL_WEBSITE_NAME));
((CheckBox)view.findViewById(R.id.feedCheckBox)).setChecked(
cursor.getInt(EntryData.COL_WEBSITE_ENABLED)==1
);
}
}