下面列出了android.widget.CheckedTextView#setChecked ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected ArrayAdapter<T> initAdapter(List<T> items)
{
return new ArrayAdapter<T>(getActivity(), android.R.layout.simple_list_item_single_choice, items)
{
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
final CheckedTextView tv = (CheckedTextView) super.getView(position, convertView, parent);
tv.setOnClickListener(v ->
{
getListView().setItemChecked(position, true);
_okButton.setEnabled(true);
});
tv.setChecked(getListView().isItemChecked(position));
return tv;
}
};
}
/**
* {@inheritDoc}
*/
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
View row = inflater.inflate(R.layout.imagemultichoicelistitem, parent, false);
ImageView imageView = (ImageView) row.findViewById(R.id.image);
imageView.setImageResource(resourceIds[position]);
CheckedTextView checkedTextView = (CheckedTextView) row.findViewById(R.id.check);
checkedTextView.setText(getItem(position));
if (position == index)
{
checkedTextView.setChecked(true);
}
return row;
}
public HeaderViewHolder(final DragSortAdapter<?> dragSortAdapter, final View itemView) {
super(dragSortAdapter, itemView);
spinHelper = (Spinner) itemView.findViewById(R.id.spin_helper);
tvSetupStatus = (TextView) itemView.findViewById(R.id.tv_setup_status);
tvSetupProvider = (TextView) itemView.findViewById(R.id.tv_setup_provider);
pbSetup = (ProgressBar) itemView.findViewById(R.id.pb_setup);
btnForget = (Button) itemView.findViewById(R.id.btn_forget);
btnInit = (Button) itemView.findViewById(R.id.btn_init);
btnSetup = (Button) itemView.findViewById(R.id.btn_setup);
ctvAutoRecover = (CheckedTextView) itemView.findViewById(R.id.ctv_auto_recover);
final HelpersAdapter adapter = new HelpersAdapter();
spinHelper.setAdapter(adapter);
spinHelper.setSelection(adapter.getPosition(TrivialBilling.getHelper()));
spinHelper.setOnItemSelectedListener(this);
btnForget.setOnClickListener(this);
btnInit.setOnClickListener(this);
btnSetup.setOnClickListener(this);
ctvAutoRecover.setChecked(TrivialBilling.isAutoRecover());
ctvAutoRecover.setOnClickListener(this);
iabHelper.addSetupListener(this);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final Integer id = cursor.getInt(0);
final ImageView visibility = (ImageView) view.findViewById(R.id.iv_visibility);
visibility.setImageDrawable(cursor.getInt(2) != 0 ? mVisibilityOn : mVisibilityOff);
visibility.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isVisible = visibility.getDrawable().equals(mVisibilityOn);
updateRecord(id, !isVisible);
}
});
CheckedTextView name = (CheckedTextView) view.findViewById(R.id.tv_name);
name.setChecked(mSelectedIds.contains(id + ""));
name.setText(cursor.getString(1));
}
@Override
@SuppressLint("ViewHolder")
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
View view = inflater.inflate(R.layout.item_icon_preference, parent, false);
CheckedTextView textView = (CheckedTextView) view.findViewById(R.id.label);
textView.setText(getItem(position));
textView.setChecked(position == mSelectedIndex);
ImageView imageView = (ImageView) view.findViewById(R.id.icon);
imageView.setImageDrawable(mImageDrawables.get(position));
return view;
}
private static void updateView(View view, State state) {
if (view instanceof CheckedTextView) {
CheckedTextView checkedTextView = (CheckedTextView) view;
checkedTextView.setText(state.field.toString());
checkedTextView.setChecked(state.checked);
}
}
private static void updateView(View view, State state) {
if (view instanceof CheckedTextView) {
CheckedTextView checkedTextView = (CheckedTextView) view;
checkedTextView.setText(state.field.toString());
checkedTextView.setChecked(state.checked);
}
}
/**
* 将textview设置为未选中状态
*/
private void setCheckedStatus(CheckedTextView textView,
CheckedTextView textView1,
CheckedTextView textView2,
CheckedTextView textView3,
CheckedTextView textView4,
LinearLayout linearLayout,
LinearLayout linearLayout1,
LinearLayout linearLayout2,
LinearLayout linearLayout3,
LinearLayout linearLayout4,
int rewardNum){
textView1.setChecked(false);
textView2.setChecked(false);
textView3.setChecked(false);
textView4.setChecked(false);
setRewardCoinUnSelectedColor(linearLayout1, textView1);
setRewardCoinUnSelectedColor(linearLayout2, textView2);
setRewardCoinUnSelectedColor(linearLayout3, textView3);
setRewardCoinUnSelectedColor(linearLayout4, textView4);
textView.toggle();
if (textView.isChecked()){
mRewardNum = rewardNum;
setRewardCoinSelectedColor(linearLayout, textView);
}else {
setRewardCoinUnSelectedColor(linearLayout, textView);
mRewardNum = 0;
}
Log.d("RewardArticleDialog", String.valueOf(textView.isChecked()) + rewardNum);
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
@SuppressLint("ViewHolder") View view = inflater.inflate(R.layout.icon_preference_item, parent, false);
CheckedTextView textView = view.findViewById(R.id.label);
textView.setText(getItem(position));
textView.setChecked(position == mSelectedIndex);
ImageView imageView = view.findViewById(R.id.icon);
imageView.setImageDrawable(mImageDrawables.get(position));
return view;
}
@NotNull
@Override
@SuppressLint("ViewHolder")
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
View view = inflater.inflate(R.layout.item_icon_preference, parent, false);
CheckedTextView textView = view.findViewById(R.id.label);
textView.setText(getItem(position));
textView.setChecked(position == mSelectedIndex);
ImageView imageView = view.findViewById(R.id.icon);
imageView.setImageDrawable(mImageDrawables.get(position));
return view;
}
@Override
public void onClick(View v) {
if (v instanceof CheckedTextView) {
CheckedTextView checkedTextView = (CheckedTextView) v;
checkedTextView.setChecked(!checkedTextView.isChecked());
}
}
@NonNull
@Override
@SuppressLint("ViewHolder")
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = ((BaseActivity) getContext()).getLayoutInflater();
View view = inflater.inflate(R.layout.item_icon_listpreference, parent, false);
CheckedTextView textView = view.findViewById(R.id.label);
textView.setText(getItem(position));
textView.setChecked(position == selectedIndex);
ImageView imageView = view.findViewById(R.id.icon);
imageView.setImageDrawable(list.get(position));
return view;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
row = mInflater.inflate(android.R.layout.simple_list_item_single_choice, parent, false);
}
CheckedTextView tv = (CheckedTextView) row.findViewById(android.R.id.text1);
tv.setText(getItem(position).toString());
tv.setChecked(mEntryIndex == position);
tv.setTextColor(Color.parseColor(colors[position]));
return row;
}
/**
* 主导航项单击事件
*/
@OnClick({
cn.tomoya.android.md.R.id.btn_nav_all,
cn.tomoya.android.md.R.id.btn_nav_good,
cn.tomoya.android.md.R.id.btn_nav_share,
cn.tomoya.android.md.R.id.btn_nav_ask,
cn.tomoya.android.md.R.id.btn_nav_pybbs
})
public void onNavigationMainItemClick(CheckedTextView itemView) {
for (CheckedTextView navItem : navMainItemList) {
navItem.setChecked(navItem.getId() == itemView.getId());
}
drawerLayout.closeDrawers();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TGMainDrawerTrackListItem item = (TGMainDrawerTrackListItem) this.getItem(position);
View view = (convertView != null ? convertView : getLayoutInflater().inflate(R.layout.view_main_drawer_check_item, parent, false));
view.setOnClickListener(getMainDrawer().getActionHandler().createGoToTrackAction(item.getTrack()));
view.setOnLongClickListener(getMainDrawer().getActionHandler().createGoToTrackWithSmartMenuAction(item.getTrack()));
CheckedTextView checkedTextView = (CheckedTextView) view.findViewById(R.id.main_drawer_check_item);
checkedTextView.setText(item.getLabel());
checkedTextView.setChecked(Boolean.TRUE.equals(item.getSelected()));
return view;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CheckedTextView view = (CheckedTextView) super.getView(position, convertView, parent);
PassphraseType positionType = getType(position);
PassphraseType currentType = getCurrentTypeFromArguments();
Set<PassphraseType> allowedTypes =
currentType.getAllowedTypes(getIsEncryptEverythingAllowedFromArguments());
// Set the item to checked it if it is the currently selected encryption type.
view.setChecked(positionType == currentType);
// Allow user to click on enabled types for the current type.
view.setEnabled(allowedTypes.contains(positionType));
return view;
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, Cursor cursor) {
MyListItem myListItem = MyListItem.fromCursor(cursor);
CheckedTextView contactName = viewHolder.mCheckedTextView;
contactName.setText(myListItem.getName());
contactName.setChecked(checkedItems.contains(myListItem.getPosition()));
final ImageView contactImage = viewHolder.mImageView;
int photoThumbnailURIIndex = cursor.getColumnIndexOrThrow(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);
String photoThumbnailString = cursor.getString(photoThumbnailURIIndex);
contactImage.setImageResource(R.drawable.ic_identicons_style_retro);
if (photoThumbnailString == null)
return;
final Uri photoThumbnailURI = Uri.parse(photoThumbnailString);
new Thread(new Runnable() {
public void run() {
try {
// Original implementation from: http://stackoverflow.com/a/6228188
// Create a 48 dip thumbnail
InputStream input = getContentResolver().openInputStream(photoThumbnailURI);
BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
onlyBoundsOptions.inJustDecodeBounds = true;
onlyBoundsOptions.inDither = true;
onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
input.close();
int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth;
Resources r = getResources();
float thumbnailSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, r.getDisplayMetrics());
double ratio = (originalSize > thumbnailSize) ? (originalSize / thumbnailSize) : 1.0;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = Integer.highestOneBit((int) Math.floor(ratio));
bitmapOptions.inDither = true;
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
input = getContentResolver().openInputStream(photoThumbnailURI);
final Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
input.close();
runOnUiThread(new Runnable() {
@Override
public void run() {
contactImage.setImageBitmap(bitmap);
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = View.inflate(context, R.layout.auth_page_item, null);
}
int count = getCount();
View llItem = convertView.findViewById(R.id.llItem);
int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 10);
if (count == 1) {
llItem.setBackgroundResource(R.drawable.list_item_single_normal);
llItem.setPadding(0, 0, 0, 0);
convertView.setPadding(dp_10, dp_10, dp_10, dp_10);
}
else if (position == 0) {
llItem.setBackgroundResource(R.drawable.list_item_first_normal);
llItem.setPadding(0, 0, 0, 0);
convertView.setPadding(dp_10, dp_10, dp_10, 0);
}
else if (position == count - 1) {
llItem.setBackgroundResource(R.drawable.list_item_last_normal);
llItem.setPadding(0, 0, 0, 0);
convertView.setPadding(dp_10, 0, dp_10, dp_10);
}
else {
llItem.setBackgroundResource(R.drawable.list_item_middle_normal);
llItem.setPadding(0, 0, 0, 0);
convertView.setPadding(dp_10, 0, dp_10, 0);
}
Platform plat = getItem(position);
ImageView ivLogo = (ImageView) convertView.findViewById(R.id.ivLogo);
Bitmap logo = getIcon(plat);
if (logo != null && !logo.isRecycled()) {
ivLogo.setImageBitmap(logo);
}
CheckedTextView ctvName = (CheckedTextView) convertView.findViewById(R.id.ctvName);
ctvName.setChecked(plat.isValid());
if (plat.isValid()) {
String userName = plat.getDb().get("nickname");
if (userName == null || userName.length() <= 0 || "null".equals(userName)) {
userName = getName(plat);
}
ctvName.setText(userName);
} else {
ctvName.setText(R.string.not_yet_authorized);
}
return convertView;
}
public void unregisterThirdPartyAccount(Platform plat, CheckedTextView ctvName) {
plat.removeAccount();
ctvName.setChecked(false);
ctvName.setText(R.string.not_yet_authorized);
}
@UiThreadTest
@Test
public void checkBoxMatchers() {
assertFalse(isChecked().matches(new Spinner(context)));
assertFalse(isNotChecked().matches(new Spinner(context)));
CheckBox checkBox = new CheckBox(context);
checkBox.setChecked(true);
assertTrue(isChecked().matches(checkBox));
assertFalse(isNotChecked().matches(checkBox));
checkBox.setChecked(false);
assertFalse(isChecked().matches(checkBox));
assertTrue(isNotChecked().matches(checkBox));
RadioButton radioButton = new RadioButton(context);
radioButton.setChecked(false);
assertFalse(isChecked().matches(radioButton));
assertTrue(isNotChecked().matches(radioButton));
radioButton.setChecked(true);
assertTrue(isChecked().matches(radioButton));
assertFalse(isNotChecked().matches(radioButton));
CheckedTextView checkedText = new CheckedTextView(context);
checkedText.setChecked(false);
assertFalse(isChecked().matches(checkedText));
assertTrue(isNotChecked().matches(checkedText));
checkedText.setChecked(true);
assertTrue(isChecked().matches(checkedText));
assertFalse(isNotChecked().matches(checkedText));
Checkable checkable =
new Checkable() {
@Override
public boolean isChecked() {
return true;
}
@Override
public void setChecked(boolean ignored) {}
@Override
public void toggle() {}
};
assertFalse(isChecked().matches(checkable));
assertFalse(isNotChecked().matches(checkable));
}