私はカスタムカレンダーを作成しています。私のカレンダーは、各ボタンのonClickリスナーを含む毎日のボタンを含むグリッドビューです。それぞれには日付を表すタグがあります。Android:タグでビューのリストを取得して特定のボタンを変更する
私は最初、私は一致するすべてのビューを取得しています、だから、特定のタグ(日付)によるレイアウトのボタンを見つけ、その後、(太字にその内容を変更する)ことで動作するように
を必要としていますタグ(イベント日付):
/**
* Get all the views which matches the given Tag recursively
* http://stackoverflow.com/questions/9920559/how-to-find-list-of-views-that-has-a-specific-tag-attribute
* @param root parent view. for e.g. Layouts
* @param tag tag to look for
* @return List of views
*/
public static List<View> findViewWithTagRecursively(ViewGroup root, Object tag){
List<View> allViews = new ArrayList<View>();
final int childCount = root.getChildCount();
for(int i=0; i<childCount; i++){
final View childView = root.getChildAt(i);
if(childView instanceof ViewGroup){
allViews.addAll(findViewWithTagRecursively((ViewGroup)childView, tag));
}
else{
final Object tagView = childView.getTag();
if(tagView != null && tagView.equals(tag))
allViews.add(childView);
}
}
return allViews;
}
次は私が大胆
Log.d(tag, "calendarFormatdate "+eventDate);
List gridcells = findViewWithTagRecursively(calendarView, eventDate);
if (gridcells.size() == 1) {
Button gridcellButton = gridcells.get(0); //this doesnt work(required Anroid.Widget.Button - FOUND Java.Lang.Object
//Object gridcellbutton = gridcells.get(0); //this works but cannot assign it to Button object
}
アンクル
私はそのテキストをそのビューからボタンを作成しようとしていますボタンとJavaオブジェクトが異なっていることを確認してください。ですが、このオブジェクトをボタンに変換して表示する方法はありますか?オブジェクトgridcellBUtton値は以下の通りです:
renaldyalisys D/GridCellAdapter: object value android.widget.Button{eb9b3a4 VFED..C. ........ 0,0-68,72 #7f0c00bc app:id/calendar_day_gridcell}
あなたの質問であまりにも多くのことが起こっています。私はあなたの問題を示すために必要最小限の本質に戻すことをお勧めします。 –
あなたの答えをありがとう、私はコードを変更します –
@BasilBourque編集 –