###前提・実現したいこと
Table.axmlで設定されている"red.png"を"blue.png"へC#から変更したいです。
###発生している問題
エラーは起きませんが、画像が変更されないです。
また、同じような方法でテキストの変更も試してみましたが、変更されなかったです。
###該当のソースコード
C#
1private Context context = null; 2 3public void ShowDialog(Context ct) { 4 context = ct; 5 var dialog = new Dialog(context); 6 AttachImageToTable(); 7 dialog.SetContentView(LayoutInflater.From(context).Inflate(Resource.Layout.Table, null)); 8 dialog.SetCanceledOnTouchOutside(true); 9 dialog.Show(); 10} 11 12private void AttachImageToTable() { 13 View inf = LayoutInflater.From(context).Inflate(Resource.Layout.Table, null); 14 FrameLayout parent = inf.FindViewById<FrameLayout>(Resource.Id.c); 15 for (int i = 0; i < parent.ChildCount; i++) { 16 var child = parent.GetChildAt(i); 17 if (child is ImageView) { 18 (child as ImageView).SetImageResource(Resource.Drawable.blue); 19 } 20 } 21}
xml
1<?xml version="1.0" encoding="utf-8"?> 2<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="fill_parent" 5 android:layout_height="fill_parent" 6 android:layout_weight="1" 7 android:shrinkColumns="0,1,2" 8 android:id="@+id/tableLayout1"> 9 <TableRow 10 android:id="@+id/tableRow1" 11 android:orientation="horizontal" 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content"> 14 <include 15 layout="@layout/TableItem" 16 android:id="@+id/a" /> 17 <include 18 layout="@layout/TableItem" 19 android:id="@+id/b" /> 20 <FrameLayout 21 android:layout_weight="1" 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 android:id="@+id/c"> 25 <ImageView 26 android:src="@drawable/red" 27 android:adjustViewBounds="true" 28 android:scaleType="fitXY" 29 android:layout_width="fill_parent" 30 android:layout_height="fill_parent" /> 31 <TextView 32 android:layout_width="wrap_content" 33 android:layout_height="wrap_content" 34 android:layout_gravity="center|center_vertical" 35 android:clickable="false" 36 android:textSize="12sp" 37 android:text="test" 38 android:textColor="#ffffff" /> 39 </FrameLayout> 40 </TableRow> 41</TableLayout>
###試したこと
・AttachImageToTable()の呼ぶタイミングを変更してみましたが、変更されませんでした。
・ImageViewにIDを設定して直接変えようとしてみましたが、変更されませんでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/17 06:20