下面列出了android.support.v7.widget.CardView#findViewById ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
CardView cardView = holder.cardView;
ImageView imageView = (ImageView)cardView.findViewById(R.id.info_image);
Drawable drawable = cardView.getResources().getDrawable(imageIds[position]);
imageView.setImageDrawable(drawable);
imageView.setContentDescription(captions[position]);
TextView textView = (TextView)cardView.findViewById(R.id.info_text);
textView.setText(captions[position]);
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onClick(position);
}
}
});
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.content_about_tab3, container, false);
LinearLayout layoutContainer = view.findViewById(R.id.changelog_container);
String[] titles = new String[]{"1.2", "1.1.4", "1.1.3", "1.1.2", "1.1.1", "1.1", "1.0"};
for (int i = 0; i < titles.length; i++) {
CardView card = (CardView) LayoutInflater.from(getContext()).inflate(R.layout.changelog_card_view, null);
TextView title = card.findViewById(R.id.changelog_card_view_title);
TextView description = card.findViewById(R.id.changelog_card_view_text);
title.setText(titles[i]);
description.setText(createText(titles.length - i));
layoutContainer.addView(card);
}
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_about_tab3, container, false);
LinearLayout layoutContainer = view.findViewById(R.id.changelog_container);
String[] titles = new String[]{"3.13", "3.12.1", "3.12", "3.11.3", "3.11.2", "3.11.1", "3.11", "3.10.2", "3.10.1", "3.10", "3.9.2", "3.9.1", "3.9",
"3.8.6", "3.8.5", "3.8.4", "3.8.3", "3.8.2", "3.8.1", "3.8", "3.7.2", "3.7.1", "3.7",
"3.6.2", "3.6.1", "3.6", "3.5", "3.4", "3.3.5", "3.3.4", "3.3.3", "3.3.2", "3.3.1",
"3.3", "3.2", "3.1.5", "3.1.4", "3.1.3", "3.1.2", "3.1.1", "3.1", "3.0.1", "3.0",
"2.0.2", "2.0.1", "2.0", "1.4", "1.3", "1.2", "1.1", "1.0"};
for (int i = 0; i < titles.length; i++) {
CardView card = (CardView) LayoutInflater.from(getContext()).inflate(R.layout.changelog_card_view, null);
TextView title = card.findViewById(R.id.changelog_card_view_title);
TextView description = card.findViewById(R.id.changelog_card_view_text);
title.setText(titles[i]);
description.setText(createText(titles.length - i));
layoutContainer.addView(card);
}
return view;
}
public Toast build() {
if (!DialogUtils.checkNull(mToast)) {
mToast.get().cancel();
}
Toast toast = new Toast(context);
if (isFill) {
toast.setGravity(gravity | Gravity.FILL_HORIZONTAL, 0, yOffset);
} else {
toast.setGravity(gravity, 0, yOffset);
}
toast.setDuration(duration);
toast.setMargin(0, 0);
if(layout==0){
CardView rootView = (CardView) LayoutInflater.from(context).inflate(R.layout.view_toast_custom, null);
TextView textView = rootView.findViewById(R.id.toastTextView);
TextView descTv = rootView.findViewById(R.id.desc);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//rootView.setElevation(elevation);
rootView.setCardElevation(elevation);
}
rootView.setRadius(radius);
rootView.setCardBackgroundColor(backgroundColor);
//rootView.setBackgroundColor(backgroundColor);
textView.setTextColor(textColor);
textView.setText(title);
if(TextUtils.isEmpty(desc)){
descTv.setVisibility(View.GONE);
}else{
descTv.setText(desc);
descTv.setVisibility(View.VISIBLE);
}
toast.setView(rootView);
}else {
View view = LayoutInflater.from(context).inflate(layout, null);
toast.setView(view);
}
mToast = new SoftReference<>(toast);
return toast;
}
private void init() {
if (isInEditMode()) {
return;
}
_popupCard = (CardView) LayoutInflater.from(getContext()).inflate(R.layout.view_group_popup, this, false);
// set the CardView color
int color = Setup.appSettings().getDesktopFolderColor();
int alpha = Color.alpha(color);
_popupCard.setCardBackgroundColor(color);
// remove elevation if CardView's background is transparent to avoid weird shadows because CardView does not support transparent backgrounds
if (alpha == 0) {
_popupCard.setCardElevation(0f);
}
_cellContainer = _popupCard.findViewById(R.id.group);
bringToFront();
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (_dismissListener != null) {
_dismissListener.onDismiss();
}
collapse();
}
});
addView(_popupCard);
_popupCard.setVisibility(View.INVISIBLE);
setVisibility(View.INVISIBLE);
_textViewGroupName = _popupCard.findViewById(R.id.group_popup_label);
}
@Override
public void refreshUI() {
TypedValue itemStoryTextColor = new TypedValue();
TypedValue itemStoryBackground = new TypedValue();
TypedValue windowBackground = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(R.attr.item_story_text_color, itemStoryTextColor, true);
theme.resolveAttribute(R.attr.item_story_background_color, itemStoryBackground, true);
theme.resolveAttribute(R.attr.windowBackground, windowBackground, true);
Resources resources = getResources();
View window=((ViewGroup) getActivity().getWindow().getDecorView());
window.setBackgroundColor(resources.getColor(windowBackground.resourceId));
int childCount = recyclerView.getChildCount();
int firstVisible = mLinearLayoutManager.findFirstVisibleItemPosition();
for (int childIndex = 0; childIndex < childCount; childIndex++) {
int viewType = mAdapter.getItemViewType(childIndex + firstVisible);
switch (viewType) {
case ThemeStoriesAdapter.Type.TYPE_HEADER:
break;
case ThemeStoriesAdapter.Type.TYPE_AVATARS:
AvatarsView avatarsView = (AvatarsView) recyclerView.getChildAt(childIndex);
avatarsView.setBackgroundColor(resources.getColor(windowBackground.resourceId));
break;
case ThemeStoriesAdapter.Type.TYPE_ITEM:
CardView cardView = (CardView) recyclerView.getChildAt(childIndex);
cardView.setCardBackgroundColor(resources.getColor(itemStoryBackground.resourceId));
TextView title = (TextView) cardView.findViewById(R.id.title);
title.setTextColor(resources.getColor(itemStoryTextColor.resourceId));
break;
}
}
invalidateCacheItem();
}
@Override
public void refreshUI() {
TypedValue itemDateTextColor = new TypedValue();
TypedValue itemStoryTextColor = new TypedValue();
TypedValue itemStoryBackground = new TypedValue();
TypedValue windowBackground = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(R.attr.item_date_text_color, itemDateTextColor, true);
theme.resolveAttribute(R.attr.item_story_text_color, itemStoryTextColor, true);
theme.resolveAttribute(R.attr.item_story_background_color, itemStoryBackground, true);
theme.resolveAttribute(R.attr.windowBackground, windowBackground, true);
Resources resources = getResources();
View window = getActivity().getWindow().getDecorView();
window.setBackgroundColor(resources.getColor(windowBackground.resourceId));
int childCount = recyclerView.getChildCount();
int firstVisible = mLinearLayoutManager.findFirstVisibleItemPosition();
for (int childIndex = 0; childIndex < childCount; childIndex++) {
int viewType = mAdapter.getItemViewType(childIndex+firstVisible);
switch (viewType) {
case DailyStoriesAdapter.Type.TYPE_HEADER:
break;
case DailyStoriesAdapter.Type.TYPE_DATE:
TextView textView = (TextView) recyclerView.getChildAt(childIndex);
textView.setTextColor(resources.getColor(itemDateTextColor.resourceId));
break;
case DailyStoriesAdapter.Type.TYPE_STORY:
CardView cardView = (CardView) recyclerView.getChildAt(childIndex);
cardView.setCardBackgroundColor(resources.getColor(itemStoryBackground.resourceId));
TextView title = (TextView) cardView.findViewById(R.id.title);
title.setTextColor(resources.getColor(itemStoryTextColor.resourceId));
break;
}
}
invalidateCacheItem();
}
public void initView() {
cardView = (CardView) view.findViewById(R.id.item1);
textView = (TextView) view.findViewById(R.id.lab_textview);
textView.setText(R.string.nightMode1);
aSwitch = (Switch) cardView.findViewById(R.id.cb);
SharedPreferences sharedPreferences = getActivity().getSharedPreferences(MyApplication.shareFilename2, getActivity().MODE_PRIVATE);
boolean checked = sharedPreferences.getBoolean("ischecked", false);
aSwitch.setChecked(checked);
switchStatus(aSwitch, MyApplication.shareFilename2);
}
private void addView(List<LeanCloudApiBean.ResultsEntity> list) {
LayoutInflater inflater = LayoutInflater.from(mContext);
//实例化一个LinearLayout
LinearLayout linear = new LinearLayout(this);
//设置LinearLayout属性(宽和高)
LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 120);
//将以上的属性赋给LinearLayout
linear.setLayoutParams(layoutParams);
ImageLoader imageLoader = new ImageLoader(VolleySingleton.getInstance().getRequestQueue(), BaseApplication.getInstance().getBitmapCache());
for (final LeanCloudApiBean.ResultsEntity lc :
list) {
// 获取需要添加的布局
CardView layout = (CardView) inflater.inflate(
R.layout.item_article_list, linear).findViewById(R.id.card_view);
if (layout.getParent() != null)
((LinearLayout) layout.getParent()).removeView(layout); // <- fix
// 将布局加入到当前布局中
linearLayout.addView(layout);
TextView title = (TextView) layout.findViewById(R.id.title);
TextView source = (TextView) layout.findViewById(R.id.source);
NetworkImageView picture = (NetworkImageView) layout.findViewById(R.id.picture);
if (lc.type == 0) {
title.setText(lc.title);
try {
source.setText(lc.source + " " + TimeUtils.DATE_FORMAT_DATE.format(TimeUtils.FULL_DATE_FORMAT_DATE.parse(lc.postTime.iso)));
} catch (ParseException e) {
e.printStackTrace();
}
if (isShowPicture) {
if (lc.imageUrl.isEmpty()) {
picture.setVisibility(View.GONE);
} else {
picture.setVisibility(View.VISIBLE);
picture.setDefaultImageResId(R.drawable.ic_default);
picture.setErrorImageResId(R.drawable.ic_default);
picture.setImageUrl(lc.imageUrl, imageLoader);
}
} else {
picture.setVisibility(View.GONE);
}
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = getIntent();
intent.putExtra("BEAN", lc);
intent.putExtra("TABLE_NAME", tableName);
intent.putExtra("BILINGUAL_READING_TAG", bilingualReadingTag);
finish();
startActivity(intent);
}
});
} else {
NativeADDataRef nativeADDataRef = lc.nativeADDataRef;
title.setText(nativeADDataRef.getTitle() != null ? nativeADDataRef.getTitle() : nativeADDataRef.getSubTitle());
source.setText("广告");
if (isShowPicture) {
picture.setImageUrl(nativeADDataRef.getImage(), imageLoader);
picture.setDefaultImageResId(R.drawable.ic_default);
picture.setErrorImageResId(R.drawable.ic_default);
} else {
picture.setVisibility(View.GONE);
}
CommonUtils.setAds(layout, lc.iflyNativeAd, nativeADDataRef);
adCardView = layout;
nativeADDataRef2 = nativeADDataRef;
}
}
}
/**
* Called by RecyclerView to display the data at the specified position. This method
* should update the contents of the {@link ConversationListItemPresenter#itemView} to reflect the item at
* the given position.
*
* @param holder The ViewHolder which should be updated to represent the contents of the
* item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
@Override
public void onBindViewHolder(ChatItemPresenter holder, final int position) {
CardView cv = holder.getCardView();
TextView itemContentTextView = (TextView)cv.findViewById(R.id.itemContentViewId);
TextView timeStampTextView = (TextView)cv.findViewById(R.id.timeStampViewId);
// TextView itemStatusTextView = (TextView)cv.findViewById(R.id.itemStatusViewId);
TextView remoteParticipantTextView = (TextView)cv.findViewById(R.id.remoteParticipantViewId);
String itemContent = "";
// Get the conversation activity item to display
ConversationActivityItem activityItem = this.conversationActivityItemList.get(position);
ConversationActivityItem.ActivityType activityType = activityItem.getType();
switch (activityType) {
case TEXTMESSAGE:
String remoteParticipantName;
MessageActivityItem messageActivityItem = (MessageActivityItem)activityItem;
itemContent = messageActivityItem.getText();
// Register callback for DisplayName and URI
messageActivityItem.getSender().addOnPropertyChangedCallback(holder.getPropertyChangeListener());
remoteParticipantName = messageActivityItem.getSender().getDisplayName();
if (messageActivityItem.getDirection() == MessageActivityItem.MessageDirection.OUTGOING) {
// ToDo: DisplayName is returned as [email protected] Fix.
remoteParticipantName = "";
}
// Set Remote participant Name
remoteParticipantTextView.setText(remoteParticipantName);
break;
case PARTICIPANTJOINED:
case PARTICIPANTLEFT:
ParticipantActivityItem participantActivityItem = (ParticipantActivityItem)activityItem;
// Register callback for DisplayName and URI
participantActivityItem.getPerson().addOnPropertyChangedCallback(holder.getPropertyChangeListener());
String activityString = (
activityType == ConversationActivityItem.ActivityType.PARTICIPANTJOINED) ? " Joined" : " Left";
String participantName = participantActivityItem.getPerson().getDisplayName();
itemContent = participantName + activityString;
break;
default:
}
// Set the timestamp
Date itemTimeStamp = activityItem.getTimestamp();
String timeString = android.text.format.DateFormat.getTimeFormat(cv.getContext()).format(itemTimeStamp);
timeStampTextView.setText(timeString);
// Set Item content
itemContentTextView.setText(itemContent);
// Set status
// @Bug: Status does not resolve correctly.
//itemStatusTextView.setText(activityItem.getStatus().toString());
}