下面列出了怎么用android.widget.CheckedTextView的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.folder_item, parent, false);
}
String folder = getItem(position);
CheckedTextView tv = (CheckedTextView) convertView.findViewById(R.id.cb_folder);
tv.setText(folder);
if (mHiddenFolders.contains(folder.hashCode())) {
// this folder was set to be hidden
tv.setChecked(false);
tv.setTextColor(Color.LTGRAY);
} else {
// set default status
tv.setChecked(true);
tv.setTextColor(Color.BLACK);
}
return convertView;
}
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);
}
/**
* {@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;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final View itemView = super.getView(position, convertView, parent);
if (itemView == null) {
return null;
}
final CheckedTextView checkedTextView = (CheckedTextView)itemView;
if (hasCheckbox(position)) {
checkedTextView.setEnabled(isEnabled(position));
} else {
checkedTextView.setCheckMarkDrawable(null);
checkedTextView.setTextColor(getResources().getColor(R.color.accent));
}
return checkedTextView;
}
private void setToggleForceSimpleMode()
{
int forceSimpleMode = sharedPref.getInt("ForceSimpleMode", 0);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.playlistCountLayout);
CheckedTextView toggleForceSimpleModeView = (CheckedTextView) findViewById(R.id.forceSimpleModeHint);
if( forceSimpleMode == 1 )
{
toggleForceSimpleModeView.setChecked(true);
if ( enableListCountSelection ) layout.setVisibility(View.INVISIBLE);
}
else
{
toggleForceSimpleModeView.setChecked(false);
if ( enableListCountSelection ) layout.setVisibility(View.VISIBLE);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (position < 0 || position >= getCount()) {
return null;
}
// Always pass in null so that we will get a new CheckedTextView. Otherwise, an item
// which was previously used as an <optgroup> element (i.e. has no check), could get
// used as an <option> element, which needs a checkbox/radio, but it would not have
// one.
convertView = super.getView(position, null, parent);
if (mItemEnabled[position] != POPUP_ITEM_TYPE_ENABLED) {
if (mItemEnabled[position] == POPUP_ITEM_TYPE_GROUP) {
// Currently select_dialog_multichoice & select_dialog_multichoice use
// CheckedTextViews. If that changes, the class cast will no longer be valid.
((CheckedTextView) convertView).setCheckMarkDrawable(null);
} else {
// Draw the disabled element in a disabled state.
convertView.setEnabled(false);
}
}
return convertView;
}
/**
* Checks if the specified text is checked.
*
* @param text the text that the {@link CheckedTextView} or {@link CompoundButton} objects display, specified as a regular expression
* @return {@code true} if the specified text is checked and {@code false} if it is not checked
*/
@SuppressWarnings("unchecked")
public boolean isTextChecked(String text){
if(config.commandLogging){
Log.d(config.commandLoggingTag, "isTextChecked(\""+text+"\")");
}
waiter.waitForViews(false, CheckedTextView.class, CompoundButton.class);
if(viewFetcher.getCurrentViews(CheckedTextView.class, true).size() > 0 && checker.isCheckedTextChecked(text))
return true;
if(viewFetcher.getCurrentViews(CompoundButton.class, true).size() > 0 && checker.isButtonChecked(CompoundButton.class, text))
return true;
return false;
}
@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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_stream_player);
settings = new Settings(getBaseContext());
mShowNavigationBarView = (CheckedTextView) findViewById(R.id.player_show_navigation_title);
mShowViewCountView = (CheckedTextView) findViewById(R.id.player_show_viewercount_title);
mAutoPlaybackView = (CheckedTextView) findViewById(R.id.player_auto_continue_playback_title);
mShowViewCountSummary = (TextView) findViewById(R.id.player_show_viewercount_title_summary);
mShowNavigationBarSummary = (TextView) findViewById(R.id.player_show_navigation_summary);
mAutoPlaybackSummary = (TextView) findViewById(R.id.player_auto_continue_playback_summary);
final Toolbar toolbar = (Toolbar) findViewById(R.id.settings_player_toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(getString(R.string.settings_stream_player_name));
}
updateSummaries();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_twitch_chat);
settings = new Settings(getBaseContext());
final Toolbar toolbar = (Toolbar) findViewById(R.id.settings_player_toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
emoteSizeSummary = (TextView) findViewById(R.id.chat_emote_size_summary);
messageSizeSummary = (TextView) findViewById(R.id.message_size_summary);
emoteStorageSummary = (TextView) findViewById(R.id.emote_storage_summary);
chatLandscapeWidthSummary = (TextView) findViewById(R.id.chat_landscape_summary);
chatLandscapeToggleSummary = (TextView) findViewById(R.id.chat_landscape_enable_summary);
chatLandscapeSwipeToShowSummary = (TextView) findViewById(R.id.chat_landscape_swipe_summary);
chatLandscapeToggle = (CheckedTextView) findViewById(R.id.chat_landscape_enable_title);
chatSwipeToShowToggle = (CheckedTextView) findViewById(R.id.chat_landscape_swipe_title);
updateSummaries();
}
/**
* @param groupPosition int
* @param childPosition int
* @param isLastChild boolean
* @param convertView View
* @param parent ViewGroup
* @return View
*/
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, null);
}
CheckedTextView txtListChild = (CheckedTextView) convertView;
txtListChild.setPadding(PADDING, PADDING, PADDING, PADDING);
txtListChild.setText(childText);
return convertView;
}
public static void setTint(@NonNull CheckedTextView textView, @ColorInt int color) {
ColorStateList sl = new ColorStateList(new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
}, new int[]{
ThemeHelper.resolveColor(textView.getContext(), R.attr.colorControlNormal),
color
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textView.setCheckMarkTintList(sl);
} else {
Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(textView.getContext(), R.drawable.abc_btn_radio_material));
DrawableCompat.setTintList(d, sl);
textView.setCheckMarkDrawable(d);
}
}
@Override public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView =
mLayoutInflater.inflate(R.layout.view_inspector_set_view_filter_listitem, parent, false);
viewHolder = new ViewHolder();
viewHolder.text1 = (CheckedTextView) convertView.findViewById(R.id.text1);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String viewClass = mViewClassList.get(position);
viewHolder.text1.setText(viewClass);
if (mViewFilter.contains(viewClass)) {
mListView.setItemChecked(position, true);
viewHolder.text1.setPaintFlags(
viewHolder.text1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
mListView.setItemChecked(position, false);
viewHolder.text1.setPaintFlags(
viewHolder.text1.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
return convertView;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent){
final View v;
ViewHolder holder;
if(convertView == null){
v = LayoutInflater.from(ctx).inflate(R.layout.row_facebook_invite_friends, parent, false);
holder = new ViewHolder();
holder.name = (CheckedTextView) v.findViewById(R.id.username);
holder.avatarImage = (ImageView) v.findViewById(R.id.user_avatar);
v.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
v = convertView;
}
Friend friend = getItem(position);
holder.name.setChecked(((ListView)parent).isItemChecked(position));
holder.name.setText(friend.getUsername());
Log.d("AptoideDebug", friend.getUsername());
Glide.with(ctx).load(friend.getAvatar()).transform(new CircleTransform(ctx)).into(holder.avatarImage);
return v;
}
public static void setTint(@NonNull CheckedTextView textView, @ColorInt int color) {
ColorStateList sl = new ColorStateList(new int[][]{
new int[]{-android.R.attr.state_checked},
new int[]{android.R.attr.state_checked}
}, new int[]{
ThemeHelper.resolveColor(textView.getContext(), R.attr.colorControlNormal),
color
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textView.setCheckMarkTintList(sl);
} else {
Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(textView.getContext(), R.drawable.abc_btn_check_material));
DrawableCompat.setTintList(d, sl);
textView.setCheckMarkDrawable(d);
}
}
/**
* {@inheritDoc}
*/
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
View row = inflater.inflate(R.layout.image_list_item, parent, false);
ImageView imageView = row.findViewById(R.id.image);
imageView.setImageResource(resourceIds[position]);
CheckedTextView checkedTextView = row.findViewById(R.id.check);
checkedTextView.setText(getItem(position));
checkedTextView.setCheckMarkDrawable(Resources.getSystem().getDrawable(mRadioDrawableId));
if (position == index) {
checkedTextView.setChecked(true);
}
return row;
}
@NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent)
{
View row = convertView;
if (row == null)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
row = inflater.inflate(this.layoutID, parent, false);
}
CheckedTextView checkedText = (CheckedTextView)row.findViewById(android.R.id.text1);
checkedText.setText(getItem(position));
checkedText.setChecked((position == index));
TextView summaryText = (TextView)row.findViewById(android.R.id.text2);
if (summaryText != null)
{
summaryText.setText(getSummary(position));
}
return row;
}
@SuppressLint("InflateParams")
private View buildView(LayoutInflater inflater) {
View view = inflater.inflate(R.layout.track_selection_dialog, null);
ViewGroup root = view.findViewById(R.id.root);
trackViews = new CheckedTextView[trackGroups.length][];
for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
TrackGroup group = trackGroups.get(groupIndex);
boolean groupIsAdaptive = trackGroupsAdaptive[groupIndex];
trackViews[groupIndex] = new CheckedTextView[group.length];
for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
if (trackIndex == 0) {
root.addView(inflater.inflate(R.layout.list_divider, root, false));
}
int trackViewLayoutId = groupIsAdaptive ? android.R.layout.simple_list_item_multiple_choice
: android.R.layout.simple_list_item_single_choice;
CheckedTextView trackView = (CheckedTextView) inflater.inflate(
trackViewLayoutId, root, false);
trackView.setText(buildTrackName(group.getFormat(trackIndex)));
if (trackInfo.getTrackFormatSupport(rendererIndex, groupIndex, trackIndex)
== RendererCapabilities.FORMAT_HANDLED) {
trackView.setFocusable(true);
trackView.setTag(Pair.create(groupIndex, trackIndex));
trackView.setOnClickListener(this);
} else {
trackView.setFocusable(false);
trackView.setEnabled(false);
}
trackViews[groupIndex][trackIndex] = trackView;
root.addView(trackView);
}
}
updateViews();
return view;
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
final CustomHolder holder;
final Context context = parent.getContext();
final View view;
if (convertView == null) {
view = LayoutInflater.from(context).inflate(android.R.layout.select_dialog_singlechoice, parent, false);
holder = new CustomHolder();
holder.checkedTextView = (CheckedTextView) view;
view.setTag(holder);
} else {
view = convertView;
holder = (CustomHolder) view.getTag();
}
final Font font = fonts.get(position);
final Typeface type = Typeface.createFromAsset(context.getAssets(), font.fontPath);
holder.checkedTextView.setTypeface(type);
holder.checkedTextView.setText(fontPreviewString != null ? fontPreviewString : font.getName());
holder.checkedTextView.setChecked(font.equals(selectedFontFace));
return view;
}
public ProfileViewHolder(View view) {
super(view);
TypedArray typedArray = obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground});
view.setBackgroundResource(typedArray.getResourceId(0, 0));
typedArray.recycle();
text = (CheckedTextView) itemView.findViewById(android.R.id.text1);
itemView.setOnClickListener(this);
}
public ProfileViewHolder(View view) {
super(view);
text = (CheckedTextView) itemView.findViewById(android.R.id.text1);
itemView.setOnClickListener(this);
itemView.setOnKeyListener(this);
initShareBtn();
initPingBtn();
}
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);
}
}
public ProfileViewHolder(View view) {
super(view);
TypedArray typedArray = obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground});
view.setBackgroundResource(typedArray.getResourceId(0, 0));
typedArray.recycle();
text = (CheckedTextView) itemView.findViewById(android.R.id.text1);
itemView.setOnClickListener(this);
}
public ProfileViewHolder(View view) {
super(view);
TypedArray typedArray = obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground});
view.setBackgroundResource(typedArray.getResourceId(0, 0));
typedArray.recycle();
text = (CheckedTextView) itemView.findViewById(android.R.id.text1);
itemView.setOnClickListener(this);
}
/**
* 将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);
}
@Override
public View getView( int position, View convertView, ViewGroup parent )
{
View view = convertView;
// This function may be called in two cases: a new view needs to be created,
// or an existing view needs to be reused
if ( view == null )
{
// Since we're using the system list for the layout, use the system inflater
final LayoutInflater inflater = (LayoutInflater)
getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
// And inflate the view android.R.layout.select_dialog_singlechoice
// Why? See com.android.internal.app.AlertController method createListView()
view = inflater.inflate( android.R.layout.select_dialog_singlechoice, parent, false);
}
if ( view != null )
{
// Find the text view from our interface
CheckedTextView tv = view.findViewById( android.R.id.text1 );
// Replace the string with the current font name using our typeface
String path = m_fontPaths.get( position );
Typeface tface = Typeface.DEFAULT;
if (!"".equals(path)) {
tface = Typeface.createFromFile(m_fontPaths.get(position));
}
tv.setTypeface( tface );
// If you want to make the selected item having different foreground or background color,
// be aware of themes. In some of them your foreground color may be the background color.
// So we don't mess with anything here and just add the extra stars to have the selected
// font to stand out.
tv.setText( m_fontNames.get( position ) );
}
return view;
}
public static String getElementType(View view) {
if (view == null) {
return null;
}
String viewType = null;
if (view instanceof CheckBox) { // CheckBox
viewType = "CheckBox";
} else if (view instanceof SwitchCompat) {
viewType = "SwitchCompat";
} else if (view instanceof RadioButton) { // RadioButton
viewType = "RadioButton";
} else if (view instanceof ToggleButton) { // ToggleButton
viewType = "ToggleButton";
} else if (view instanceof Button) { // Button
viewType = "Button";
} else if (view instanceof CheckedTextView) { // CheckedTextView
viewType = "CheckedTextView";
} else if (view instanceof TextView) { // TextView
viewType = "TextView";
} else if (view instanceof ImageButton) { // ImageButton
viewType = "ImageButton";
} else if (view instanceof ImageView) { // ImageView
viewType = "ImageView";
} else if (view instanceof RatingBar) {
viewType = "RatingBar";
} else if (view instanceof SeekBar) {
viewType = "SeekBar";
}
return viewType;
}
@NonNull
@Override
@SuppressWarnings("ConstantConditions")
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
CheckedTextView text = (CheckedTextView) super.getView(position, convertView, parent);
text.setText(getItem(position).getFormal(context));
return text;
}
/**
* Sets the checked status of a checkable.
*
* @param viewId The view id.
* @param checked The checked status;
* @return The BaseViewHolder for chaining.
*/
public BaseViewHolder setChecked(int viewId, boolean checked) {
View view = getView(viewId);
// View unable cast to Checkable
if (view instanceof CompoundButton) {
((CompoundButton) view).setChecked(checked);
} else if (view instanceof CheckedTextView) {
((CheckedTextView) view).setChecked(checked);
}
return this;
}
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
map = naverMap;
naverMap.setLocationSource(locationSource);
CheckedTextView none = findViewById(R.id.location_tracking_mode_none);
CheckedTextView noFollow = findViewById(R.id.location_tracking_mode_no_follow);
CheckedTextView follow = findViewById(R.id.location_tracking_mode_follow);
CheckedTextView face = findViewById(R.id.location_tracking_mode_face);
none.setOnClickListener(v -> naverMap.setLocationTrackingMode(LocationTrackingMode.None));
noFollow.setOnClickListener(v -> naverMap.setLocationTrackingMode(LocationTrackingMode.NoFollow));
follow.setOnClickListener(v -> naverMap.setLocationTrackingMode(LocationTrackingMode.Follow));
face.setOnClickListener(v -> naverMap.setLocationTrackingMode(LocationTrackingMode.Face));
naverMap.addOnOptionChangeListener(() -> {
LocationTrackingMode mode = naverMap.getLocationTrackingMode();
none.setChecked(mode == LocationTrackingMode.None);
noFollow.setChecked(mode == LocationTrackingMode.NoFollow);
follow.setChecked(mode == LocationTrackingMode.Follow);
face.setChecked(mode == LocationTrackingMode.Face);
locationSource.setCompassEnabled(mode == LocationTrackingMode.Follow || mode == LocationTrackingMode.Face);
});
naverMap.setLocationTrackingMode(LocationTrackingMode.Follow);
}