私はこの LayoutInflater で完全に迷っています。コード内の項目をリモート レイアウトにある項目にリンクしようとしています。インフレータ作成の 3 つの異なるバージョンを試しました。それらのどれも機能しません。ただし、このバージョンが最も広く使用されているようです。インフレータの文字化けの一部を次に示します。
setContentView(R.layout.browse);
LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ImageButton editBrowseButton = (ImageButton) li.inflate(R.layout.row, null).findViewById(R.id.imageButton1);
editBrowseButton.setAlpha(50);
これは、何かが足りないような気がします。何かを返す必要がありますか? .setAlpha には意味がありません。インレイターをテストするために入れただけです。もちろん、透明度は変わりません。onClickListner を追加しても機能しません。ただし、例外はありません。アクティビティは正常に開始されます。以下は、row.xml に関連する XML コードです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="true"
>
<TextView
android:id= "@+id/txtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "Item"
android:focusable="true"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="false"
>
<ImageButton
android:src="@drawable/editbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton1"
></ImageButton>
</TableRow>
</LinearLayout>
EDIT_01
新しいアプローチが試行され、失敗しました。同じ結果です。何も起こりません。
setContentView(R.layout.browse);
LayoutInflater li = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup rowView = (ViewGroup) li.inflate(R.layout.row, null);
LinearLayout rowLinLay = (LinearLayout) rowView
.findViewById(R.id.linearLayout1);
TableRow rowTableRow = (TableRow)rowLinLay.findViewById(R.id.tableRow2);
ImageButton editBrowseButton = (ImageButton) rowTableRow
.findViewById(R.id.imageButton1);
EDIT_02
setContentView(R.layout.browse);
ExpandableListView browseView = (ExpandableListView) findViewById(android.R.id.list);
LayoutInflater li = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = (View) li.inflate(R.layout.row, null);
TableRow rowTable = (TableRow) rowView.findViewById(R.id.tableRow2);
ImageButton editBrowseButton = (ImageButton) rowTable
.findViewById(R.id.imageButton1);
editBrowseButton.setAlpha(100);