如何使用用户首选项和复选框显示正在进行的通知?我想显示 MainActiviy 中的电池电量:
private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL,-1);
. . .
String[] statusbatt = {
"Battery level: " +level+"%",
. . .};
ListView lvStatus = (ListView) findViewById(R.id.lv_status);
lvStatus.setAdapter(new ArrayAdapter<String>(MainActivity.this, R.layout.list, statusbatt));
info.getListViewSize(lvStatus);
}
};
设置首选项:
public class Settings extends SettingsActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
final CheckBoxPreference checkboxPref = (CheckBoxPreference) getPreferenceManager()
.findPreference("Checkbox");
////// here the check box code for notfication
}
}
如您所见,我不知道该怎么做。有什么帮助吗?settings.xml 中的复选框:
<CheckBoxPreference
android:defaultValue="true"
android:key="first"
android:summary="@string/summary_show"
android:title="@string/Show_notifications" />