2

私はこの 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);
4

2 に答える 2

0

何をしようとしているのかわかりません。AFAIK LayoutInflaterは、リソースxmlファイルから「ビューを作成」するためのものです。少なくとも、それは私が:Dに使用するものです。

まず、「TableRowは常にTableLayoutの子として使用する必要があります」-つまり、xmlは私にも面白く見えます-単純なLinearLayoutが適しています。(しかし、それは側ではありません)

とにかく-私がコードで見た問題は、あなたが膨らませたビューが添付されていないことです(2番目のパラメンターはnullであり、あなたがそれをぶら下げたままにするよりも)。

エントリを複製する場合は、n回作成し、次のようにします。

setContentView(R.layout.browse);

LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout row = li.inflate(R.layout.row, null);
findViewById(/*id of element you want the row to be added to*/).add(row); //now row is attached
final ImageButton editBrowseButton = (ImageButton) row.findViewById(R.id.imageButton1); //so this is live, visible etc
editBrowseButton.setAlpha(50); //this should work than
于 2011-12-13T22:50:30.933 に答える
0

今、私はあなたの質問全体を見ることができます:-)

 LinearLayout layout = (LinearLayout) li.inflate( R.layout.linearLayout1, null); 
 TableRow tableRow = (TableRow) linearLayout1.findViewById(R.layout.tableRow2); 
 ImageButton editBrowseButton = (ImageButton) tableRow.findViewById(R.id.imageButton1); 
于 2011-06-30T22:20:26.930 に答える