下面列出了android.widget.CheckBox#setChecked ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void OnItemClick(View v, int Position, CheckBox checkBox) {
String filapath = fileTraversal.filecontent.get(Position);
if (checkBox.isChecked()) {
checkBox.setChecked(false);
mSendImgData.removeSendImg(filapath);
} else {
try {
if (mSendImgData.getSendImgs().size() >= 1) {
Toast.makeText(getApplicationContext(), R.string.send_tomanay_pics, Toast.LENGTH_SHORT).show();
} else {
checkBox.setChecked(true);
Log.i("img", "img choise position->" + Position);
ImageView imageView = iconImage(filapath, Position, checkBox);
if (imageView != null) {
hashImage.put(Position, imageView);
mSendImgData.addSendImg(filapath);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
updateCount(mMenuItem);
}
/**
* {@inheritDoc}
*/
@Override
public void setAnswer(String answer) {
Log.i(TAG, "[" + id + "]setAnswer() --> " + answer);
this.answer = (answer == null) ? "" : answer;
// Update UI if visible
if (isViewActive()) {
for (CheckBox c : cblist) {
String label = c.getText().toString();
String value = String.valueOf(c.getTag());
if (answer.contains(value)) {
c.setChecked(true);
} else {
c.setChecked(false);
}
}
}
}
@Override
public void OnItemClick(View v, int Position, CheckBox checkBox) {
String filapath = fileTraversal.filecontent.get(Position);
if (checkBox.isChecked()) {
checkBox.setChecked(false);
mSendImgData.removeSendImg(filapath);
} else {
try {
if (mSendImgData.getSendImgs().size() >= 1) {
Toast.makeText(getApplicationContext(), R.string.send_tomanay_pics, Toast.LENGTH_SHORT).show();
} else {
checkBox.setChecked(true);
Log.i("img", "img choise position->" + Position);
ImageView imageView = iconImage(filapath, Position, checkBox);
if (imageView != null) {
hashImage.put(Position, imageView);
mSendImgData.addSendImg(filapath);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
updateCount(mMenuItem);
}
public void suggestionSubscriptionUpdated(Suggestion model) {
CheckBox checkbox = (CheckBox) headerView.findViewById(R.id.uv_subscribe_checkbox);
if (suggestion.isSubscribed()) {
Toast.makeText(getActivity(), R.string.uv_msg_subscribe_success, Toast.LENGTH_SHORT).show();
checkbox.setChecked(true);
} else {
Toast.makeText(getActivity(), R.string.uv_msg_unsubscribe, Toast.LENGTH_SHORT).show();
checkbox.setChecked(false);
}
displaySuggestion(view, suggestion);
if (getActivity() instanceof ForumActivity)
((ForumActivity) getActivity()).suggestionUpdated(model);
}
@OnClick(R.id.filter_select_all)
public void onClickSelectAll(View v) {
mAdapter.clearFilter();
for (CheckBox cb : filterList) {
cb.setChecked(true);
}
closeNavDrawer();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mIsMovie = getIntent().getExtras().getBoolean("isMovie");
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (!mIsMovie)
mToolbar.setTitle(getString(R.string.updateTvShowsTitle));
setSupportActionBar(mToolbar);
mTypeface = TypefaceUtils.getRobotoLight(this);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
mClearLibrary = (CheckBox) findViewById(R.id.checkBox);
mClearLibrary.setTypeface(mTypeface);
mClearLibrary.setChecked(false);
mClearLibrary.setOnCheckedChangeListener(getOnCheckedChangeListener(true));
mRemoveUnavailableFiles = (CheckBox) findViewById(R.id.checkBox2);
mRemoveUnavailableFiles.setTypeface(mTypeface);
mRemoveUnavailableFiles.setChecked(false);
mRemoveUnavailableFiles.setOnCheckedChangeListener(getOnCheckedChangeListener(false));
mFileSourcesDescription = (TextView) findViewById(R.id.file_sources_description);
mFileSourcesDescription.setTypeface(mTypeface);
mUpdateLibraryDescription = (TextView) findViewById(R.id.update_library_description);
mUpdateLibraryDescription.setTypeface(mTypeface);
mFileSourcesButton = (Button) findViewById(R.id.select_file_sources_button);
mFileSourcesButton.setTypeface(mTypeface);
mUpdateLibraryButton = (Button) findViewById(R.id.start_update_button);
mUpdateLibraryButton.setTypeface(mTypeface);
}
/**
* 隐藏多功能布局
*/
private void hideMultiLayout() {
//把其他checkbox的选中状态取消
if (-1 != checkedId) {
CheckBox box = (CheckBox) findViewById(checkedId);
box.setChecked(false);
checkedId = -1;
}
layout_multi.setVisibility(View.GONE);
KeyboardUtils.updateSoftInputMethod(this, WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
isMultiLayoutShowing = false;
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
View cv = convertView;
if (cv == null) {
cv = mInflater.inflate(R.layout.item_irkitdevice_list, parent, false);
} else {
cv = convertView;
}
final VirtualDeviceContainer device = getItem(position);
String name = device.getLabel();
TextView nameView = (TextView) cv.findViewById(R.id.devicelist_package_name);
nameView.setText(name);
Drawable icon = device.getIcon();
if (icon != null) {
ImageView iconView = (ImageView) cv.findViewById(R.id.devicelist_icon);
iconView.setImageDrawable(icon);
}
CheckBox removeCheck = (CheckBox) cv.findViewById(R.id.delete_check);
if (mIsRemoved) {
removeCheck.setVisibility(View.VISIBLE);
removeCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
mIsRemoves.set(position, b);
}
});
removeCheck.setChecked(device.isRemove());
removeCheck.setFocusable(false);
} else {
removeCheck.setVisibility(View.GONE);
removeCheck.setOnCheckedChangeListener(null);
}
return cv;
}
/**
* Updates the barter types checkboxes
*
* @param barterTypes A list of barter types chosen for the book
*/
private void setCheckBoxesForBarterTypes(final List<String> barterTypes) {
if (barterTypes != null) {
for (final CheckBox checkBox : mBarterTypeCheckBoxes) {
if (barterTypes.contains(checkBox
.getTag(R.string.tag_barter_type))) {
checkBox.setChecked(true);
} else {
checkBox.setChecked(false);
}
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_bot);
resetView();
InstanceConfig instance = (InstanceConfig)MainActivity.instance;
CheckBox checkbox = (CheckBox) findViewById(R.id.forkingCheckBox);
checkbox.setChecked(instance.allowForking);
}
protected void loadUserList() {
LinearLayout userListContainer = (LinearLayout)findViewById(R.id.user_list_container);
//ArrayList<UserSnsInfo> userSnsList = Share.snsData.userSnsList;
checkBoxList.clear();
userListContainer.removeAllViews();
//userSnsList.get(i).snsList.size();
ArrayList<UserSnsInfo> snsSizeRank = Share.snsData.userSnsList;//new ArrayList<UserSnsInfo>(userSnsList);
Collections.sort(snsSizeRank, new Comparator<UserSnsInfo>() {
@Override
public int compare(UserSnsInfo lhs, UserSnsInfo rhs) {
if (rhs.snsList.size() - lhs.snsList.size() > 0) {
return 1;
} else if (rhs.snsList.size() - lhs.snsList.size() < 0) {
return -1;
} else {
return 0;
}
}
});
UserSnsInfo userSnsInfo2=null;
for (int i=0;i<snsSizeRank.size();i++) {
userSnsInfo2 = snsSizeRank.get(i);
CheckBox userCheckBox = new CheckBox(this);
userCheckBox.setText(userSnsInfo2.authorName + "(" + userSnsInfo2.userId + ")" + "(" + String.format(getString(R.string.user_moment_count), userSnsInfo2.snsList.size()) + ")");
userListContainer.addView(userCheckBox);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)userCheckBox.getLayoutParams();
layoutParams.setMargins(5, 5, 5, 5);
userCheckBox.setLayoutParams(layoutParams);
userCheckBox.setChecked(true);
userCheckBox.setTag(userSnsInfo2.userId);
checkBoxList.add(userCheckBox);
}
}
@Override
protected void onBindData(EasyRVHolder viewHolder, int position, final Source item) {
CheckBox box = viewHolder.getView(R.id.cb_item_source_setting);
box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
checkedMap.put(item.id, isChecked);
}
});
box.setChecked(checkedMap.get(item.id));
box.setText(item.name);
}
private void showSendLogDialog() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
SEND_LOG_ID_REQUEST);
return;
}
String[] items = new String[]{(String) getText(R.string.as_attachment), (String) getText(R.string.as_text)};
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") View includeDeviceInfoView = inflater.inflate(R.layout.dialog_send_log, null, false);
final CheckBox includeDeviceInfoCheckBox = (CheckBox) includeDeviceInfoView.findViewById(android.R.id.checkbox);
// allow user to choose whether or not to include device info in report, use preferences for persistence
includeDeviceInfoCheckBox.setChecked(PreferenceHelper.getIncludeDeviceInfoPreference(this));
includeDeviceInfoCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
PreferenceHelper.setIncludeDeviceInfoPreference(LogcatActivity.this, isChecked);
}
});
new android.app.AlertDialog.Builder(this)
.setTitle(R.string.send_log_title)
.setView(includeDeviceInfoView)
.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendLogToTargetApp(which == 1, includeDeviceInfoCheckBox.isChecked());
dialog.dismiss();
}
})
.show();
}
@NonNull
@Override
public View getView(int position, View view, @NonNull ViewGroup parent) {
Context context = parent.getContext();
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(resId, parent, false);
}
CheckBox box = (CheckBox) view.findViewById(android.R.id.checkbox);
RadioButton button = (RadioButton) view.findViewById(android.R.id.button1);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
CharSequence filename = objects.get(position);
text1.setText(filename);
if (multiMode) {
box.setChecked(checkedItems[position]);
} else {
button.setChecked(checked == position);
}
Date lastModified = SaveLogHelper.getLastModifiedDate(filename.toString());
DateFormat dateFormat = DateFormat.getDateTimeInstance();
text2.setText(dateFormat.format(lastModified));
return view;
}
private void updateSoundCheckbox(View rootView) {
CheckBox chkDeviceSoundEnabled = (CheckBox) rootView.findViewById(R.id.chkDeviceSoundEnabled);
chkDeviceSoundEnabled.setChecked(AppState.getInstance().isDeviceSoundEnabled);
}
/**
* Prepare the feature draw limits and defaults
*
* @param context
* @param geoPackage
* @param featureTable
* @param pointAlpha
* @param lineAlpha
* @param polygonAlpha
* @param polygonFillAlpha
* @param pointColor
* @param lineColor
* @param pointRadius
* @param lineStroke
* @param polygonColor
* @param polygonStroke
* @param polygonFill
* @param polygonFillColor
*/
public static void prepareFeatureDraw(Context context, GeoPackage geoPackage, String featureTable, EditText pointAlpha, EditText lineAlpha, EditText polygonAlpha, EditText polygonFillAlpha,
EditText pointColor, EditText lineColor, EditText pointRadius, EditText lineStroke,
EditText polygonColor, EditText polygonStroke, CheckBox polygonFill, EditText polygonFillColor) {
FeatureTableStyles featureTableStyles = new FeatureTableStyles(geoPackage, featureTable);
// Set feature limits
pointAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
0, 255)});
lineAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
0, 255)});
polygonAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
0, 255)});
polygonFillAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
0, 255)});
// Set default feature attributes
FeatureTiles featureTiles = new DefaultFeatureTiles(context);
String defaultColor = "#000000";
StyleRow pointStyle = featureTableStyles.getTableStyle(GeometryType.POINT);
if(pointStyle != null){
mil.nga.geopackage.style.Color pointStyleColor = pointStyle.getColorOrDefault();
pointColor.setText(pointStyleColor.getColorHex());
pointAlpha.setText(String.valueOf(pointStyleColor.getAlpha()));
pointRadius.setText(new DecimalFormat("0.0#").format(pointStyle.getWidthOrDefault() / 2.0));
}else{
Paint pointPaint = featureTiles.getPointPaint();
pointColor.setText(defaultColor);
pointAlpha.setText(String.valueOf(pointPaint.getAlpha()));
pointRadius.setText(String.valueOf(featureTiles.getPointRadius()));
}
StyleRow lineStyle = featureTableStyles.getTableStyle(GeometryType.LINESTRING);
if(lineStyle != null){
mil.nga.geopackage.style.Color lineStyleColor = lineStyle.getColorOrDefault();
lineColor.setText(lineStyleColor.getColorHex());
lineAlpha.setText(String.valueOf(lineStyleColor.getAlpha()));
lineStroke.setText(new DecimalFormat("0.0#").format(lineStyle.getWidthOrDefault()));
}else{
Paint linePaint = featureTiles.getLinePaintCopy();
lineColor.setText(defaultColor);
lineAlpha.setText(String.valueOf(linePaint.getAlpha()));
lineStroke.setText(String.valueOf(linePaint.getStrokeWidth()));
}
StyleRow polygonStyle = featureTableStyles.getTableStyle(GeometryType.POLYGON);
if(polygonStyle != null){
mil.nga.geopackage.style.Color polygonStyleColor = polygonStyle.getColorOrDefault();
polygonColor.setText(polygonStyleColor.getColorHex());
polygonAlpha.setText(String.valueOf(polygonStyleColor.getAlpha()));
polygonStroke.setText(new DecimalFormat("0.0#").format(polygonStyle.getWidthOrDefault()));
mil.nga.geopackage.style.Color polygonStyleFillColor = polygonStyle.getFillColor();
polygonFill.setChecked(polygonStyleFillColor != null);
if(polygonStyleFillColor != null){
polygonFillColor.setText(polygonStyleFillColor.getColorHex());
polygonFillAlpha.setText(String.valueOf(polygonStyleFillColor.getAlpha()));
}else{
polygonFillColor.setText(defaultColor);
polygonFillAlpha.setText(String.valueOf(255));
}
}else{
Paint polygonPaint = featureTiles.getPolygonPaintCopy();
polygonColor.setText(defaultColor);
polygonAlpha.setText(String.valueOf(polygonPaint.getAlpha()));
polygonStroke.setText(String.valueOf(polygonPaint.getStrokeWidth()));
polygonFill.setChecked(featureTiles.isFillPolygon());
Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy();
polygonFillColor.setText(defaultColor);
polygonFillAlpha.setText(String.valueOf(polygonFillPaint.getAlpha()));
}
}
@Override
protected void onBindDialogView(View view) {
LinearLayout container = view.findViewById(R.id.layoutContainer);
linearLayouts.clear();
checkBoxes.clear();
ArrayList<Integer> results = lg.getMenuShownList();
gameOrder = lg.getOrderedGameList();
TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
int padding = (int) (getContext().getResources().getDimension(R.dimen.dialog_menu_layout_padding));
int margin = (int) (getContext().getResources().getDimension(R.dimen.dialog_menu_button_margin));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(margin, 0, margin, 0);
ArrayList<String> sortedGameList = lg.getOrderedGameNameList(getContext().getResources());
for (int i = 0; i < lg.getGameCount(); i++) {
LinearLayout entry = new LinearLayout(getContext());
entry.setBackgroundResource(typedValue.resourceId);
entry.setPadding(padding, padding, padding, padding);
entry.setOnClickListener(this);
CheckBox checkBox = new CheckBox(getContext());
checkBox.setLayoutParams(layoutParams);
int index = gameOrder.indexOf(i);
checkBox.setChecked(results.get(index) == 1);
TextView textView = new TextView(getContext());
textView.setTypeface(null, Typeface.BOLD);
textView.setText(sortedGameList.get(i));
entry.addView(checkBox);
entry.addView(textView);
checkBoxes.add(checkBox);
linearLayouts.add(entry);
container.addView(entry);
}
super.onBindDialogView(view);
}
public void enDisUseSSL(boolean en, boolean checked) {
CheckBox c = (CheckBox)v.findViewById(R.id.cloud_use_ssl_checkbox);
c.setEnabled(en);
c.setChecked(checked);
}
public View getView(int position, View convertView, ViewGroup parent)
{
// day of week to display
DayOfWeek calendar = daysOfWeekList.get(position);
//System.out.println(String.valueOf(position));
// The child views in each row.
TextView textViewDisplayName;
CheckBox checkBox;
// Create a new row view
if (convertView == null)
{
convertView = inflater.inflate(R.layout.days_of_week_preference_list_item, parent, false);
// Find the child views.
textViewDisplayName = convertView.findViewById(R.id.days_of_week_pref_dlg_item_display_name);
checkBox = convertView.findViewById(R.id.days_of_week_pref_dlg_item_checkbox);
// Optimization: Tag the row with it's child views, so we don't
// have to
// call findViewById() later when we reuse the row.
convertView.setTag(new DayOfWeekViewHolder(textViewDisplayName, checkBox));
// If CheckBox is toggled, update the Contact it is tagged with.
checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
DayOfWeek dayOfWeek = (DayOfWeek) cb.getTag();
dayOfWeek.checked = cb.isChecked();
}
});
}
// Reuse existing row view
else
{
// Because we use a ViewHolder, we avoid having to call
// findViewById().
DayOfWeekViewHolder viewHolder = (DayOfWeekViewHolder) convertView.getTag();
textViewDisplayName = viewHolder.textViewDisplayName;
checkBox = viewHolder.checkBox;
}
// Tag the CheckBox with the Contact it is displaying, so that we
// can
// access the Contact in onClick() when the CheckBox is toggled.
checkBox.setTag(calendar);
// Display Contact data
textViewDisplayName.setText(calendar.name);
checkBox.setChecked(calendar.checked);
return convertView;
}
/**
* @param activity Activity
* @param mainObject Object
* @param dividerTop boolean
* @return TableRow
*/
public static TableRow createStreamTable(Activity activity, final Object mainObject, boolean dividerTop, int heading)
{
TableRow tableRow = new TableRow(activity);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
LinearLayout linearLayout = new LinearLayout(activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if (dividerTop)
{
//add divider
linearLayout.addView(Util.addDivider(activity));
}
TextView textViewName = new TextView(activity);
textViewName.setText(heading);
textViewName.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
textViewName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
linearLayout.addView(textViewName);
//get possible providers
final Object[] objects = PipelineBuilder.getInstance().getPossibleStreamConnections(mainObject);
//
if (objects.length > 0) {
for (int i = 0; i < objects.length; i++) {
CheckBox checkBox = new CheckBox(activity);
checkBox.setText(objects[i].getClass().getSimpleName());
checkBox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
Object[] providers = PipelineBuilder.getInstance().getStreamConnections(mainObject);
if (providers != null) {
for (Object provider : providers) {
if (objects[i].equals(provider)) {
checkBox.setChecked(true);
break;
}
}
}
final int count = i;
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
final Object o = objects[count];
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
PipelineBuilder.getInstance().addStreamConnection(mainObject, (Provider) o);
} else {
PipelineBuilder.getInstance().removeStreamConnection(mainObject, (Provider) o);
}
}
});
linearLayout.addView(checkBox);
}
} else
{
return null;
}
tableRow.addView(linearLayout);
return tableRow;
}