Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android LayoutInflater不';t似乎与布局中的id链接_Android_Layout Inflater - Fatal编程技术网

Android LayoutInflater不';t似乎与布局中的id链接

Android LayoutInflater不';t似乎与布局中的id链接,android,layout-inflater,Android,Layout Inflater,我完全迷路于这种更平坦的布局。我试图将代码中的项与远程布局中的项链接起来。我尝试了三种不同版本的充气机。它们都不起作用。然而,这个版本似乎是使用最广泛的。下面是一段充气机的声音: setContentView(R.layout.browse); LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final ImageButton editBrowseButto

我完全迷路于这种更平坦的布局。我试图将代码中的项与远程布局中的项链接起来。我尝试了三种不同版本的充气机。它们都不起作用。然而,这个版本似乎是使用最广泛的。下面是一段充气机的声音:

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>
编辑\u 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);

现在我可以看到你的整个问题了:-)


现在我可以看到你的整个问题了:-)


我不知道你想做什么。AFAIK LayoutInflater用于从资源xml文件“创建视图”。好吧,至少这就是我用它的目的:D

首先,“TableRow应始终用作TableLayout的子级”-因此xml看起来也很有趣-简单的线性布局会很好。(但这不在一边)

无论如何-我看到代码的问题是,您充气的视图没有附加(第二个参数为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

我不知道你想做什么。AFAIK LayoutInflater用于从资源xml文件“创建视图”。好吧,至少这就是我用它的目的:D

首先,“TableRow应始终用作TableLayout的子级”-因此xml看起来也很有趣-简单的线性布局会很好。(但这不在一边)

无论如何-我看到代码的问题是,您充气的视图没有附加(第二个参数为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

TableRow TableRow=(TableRow)li.充气(R.layout.tableRow2,null);ImageButton编辑浏览按钮=(ImageButton)tableRow.findViewById(R.id.imageButton1);构造函数不喜欢“li.inflate(R.layout.tableRow2,null)”tableRow2不是布局。如果我将同一行更改为“R.id.tableRow2”,活动将失败。此外,我注意到上面的linearlayout标记被截断。tableRow2 tablerow位于linearlayout内部。这有关系吗?如果要使用layoutInflator.inflate(resource,null),确保您知道潜在的副作用:TableRow TableRow=(TableRow)li.inflate(R.layout.tableRow2,null);ImageButton editBrowseButton=(ImageButton)TableRow.findViewById(R.id.imageButton1);构造函数不喜欢“li.inflate(R.layout.tableRow2,null)”tableRow2不是布局。如果我将同一行更改为“R.id.tableRow2”,活动将失败。此外,我注意到上面的linearlayout标记被截断。tableRow2 tablerow位于linearlayout的内部。这有关系吗?如果要使用layoutInflator.inflate(资源,null),请确保您了解潜在的副作用:抱歉!它不允许我将LinearLayout1作为布局传递。布局的名称为row:(是的,您尝试过id吗?li.inflate(R.id.LinearLayout1,null);您能看到我在做什么吗。布局不应称为row,它应该是browse(与setContentView一起使用的xml文件)是的,我尝试了所有可能的组合。我得到了这个资源异常:当我使用ID代替布局时,资源ID#0x7f050019类型#0x12无效。真正有趣的是,如果我使用上面显示的edit_02格式mAlpha(在variables debug窗口中)从255更新到100。但是按钮的透明度没有改变。它几乎像是对按钮进行了更改,只是不知道它。很抱歉!它不会让我将LinearLayout1作为布局传递。布局的名称是row:(是的,那么你试过id吗?li.inflate(R.id.LinearLayout1,null);您能看到我在做什么吗?布局不应称为行,而应称为浏览(与setContentView一起使用的xml文件)是的,我尝试了所有可能的组合。我得到了这个资源异常:当我使用ID代替布局时,资源ID#0x7f050019类型#0x12无效。真正有趣的是,如果我使用上面显示的edit_02格式mAlpha(在variables debug窗口中)从255更新到100。但是按钮的透明度没有改变。它几乎像是对按钮做了改变,只是不知道而已。
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