是否可以动态添加AndroidAnnotation@EViewGroups,而不是直接使用传统的充气工具?
我正在尝试使用Android注释,并在单击我的createNewRow按钮时动态添加布局组件。应用程序运行并显示在activity_main.xml中定义的默认行,单击createNewButton后,我会在调试器中看到附加到mydynamicTable的子项,但不会显示新的子项。以下是我的主要活动XML: 活动\u main.xml是否可以动态添加AndroidAnnotation@EViewGroups,而不是直接使用传统的充气工具?,android,android-layout,android-inflate,android-annotations,Android,Android Layout,Android Inflate,Android Annotations,我正在尝试使用Android注释,并在单击我的createNewRow按钮时动态添加布局组件。应用程序运行并显示在activity_main.xml中定义的默认行,单击createNewButton后,我会在调试器中看到附加到mydynamicTable的子项,但不会显示新的子项。以下是我的主要活动XML: 活动\u main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/inflateLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="net.richardriley.inflate.app.MainActivity">
<Button
android:id="@+id/createNewRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/newRowButton"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/dynamicTable">
<TableRow>
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="@+id/inflatedRowTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inflatedRowLabel"/>
<Button
android:id="@+id/inflatedRowButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/defaultNewRowText"
/>
</merge>
最后,我的主要活动是java本身:
MainActivity.java
package net.richardriley.inflate.app;
import android.content.Context;
import android.widget.Button;
import android.widget.TableRow;
import android.widget.TextView;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
/**
* inflate : Created by rgr on 20/03/14.
*/
@EViewGroup(R.layout.inflatedrow)
public class InflatedRow extends TableRow {
@ViewById
Button inflatedRowButton;
@ViewById
TextView inflatedRowTextView;
public InflatedRow(Context context) {
super(context);
}
}
package net.richardriley.inflate.app;
import android.support.v7.app.ActionBarActivity;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import org.androidannotations.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static ch.qos.logback.classic.android.BasicLogcatConfigurator.configureDefaultContext;
@OptionsMenu(R.menu.main)
@EActivity(R.layout.activity_main)
public class MainActivity extends ActionBarActivity {
static {
configureDefaultContext();
log = LoggerFactory.getLogger(MainActivity.class);
}
@ViewById
LinearLayout inflateLayout;
@ViewById
TableLayout dynamicTable;
public MainActivity() {
}
protected static Logger log;
@Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=new InflatedRow_(this);
dynamicTable.addView(inflatedRow,0);
/*LayoutInflater layoutInflater= (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.inflatedrow,null);
dynamicTable.addView(view);*/
}
@OptionsItem
void openSettingsSelected(){
log.info("Hello");
}
}
在createNewRow中,如果我直接使用充气机服务,它会工作
我错过了什么
非常感谢。而不是“查看充气行=新建充气行(此);”我使用'View inflatedRow=inflatedRow.build(this);'。这是为自定义控件编写的,我也需要为合并的控件组编写。所以我在一定程度上犯了错
@Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
或者(不知道这是否会继续得到支持:
@Click
void createNewRow() {
log.info("clicked");
/*View inflatedRow = InflatedRow_.build(this);*/
InflatedRow_ inflatedRow = new InflatedRow_(this);
inflatedRow.onFinishInflate();
dynamicTable.addView(inflatedRow, 0);
}
我使用的不是“查看充气行=新建充气行(this)”,而是“查看充气行=充气行(build)(this)”。这是为自定义控件编写的文档,我也需要为合并的控件组编写。因此,我在一定程度上犯了错
@Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
或者(不知道这是否会继续得到支持:
@Click
void createNewRow() {
log.info("clicked");
/*View inflatedRow = InflatedRow_.build(this);*/
InflatedRow_ inflatedRow = new InflatedRow_(this);
inflatedRow.onFinishInflate();
dynamicTable.addView(inflatedRow, 0);
}
我使用的不是“查看充气行=新建充气行(this)”,而是“查看充气行=充气行(build)(this)”。这是为自定义控件编写的文档,我也需要为合并的控件组编写。因此,我在一定程度上犯了错
@Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
或者(不知道这是否会继续得到支持:
@Click
void createNewRow() {
log.info("clicked");
/*View inflatedRow = InflatedRow_.build(this);*/
InflatedRow_ inflatedRow = new InflatedRow_(this);
inflatedRow.onFinishInflate();
dynamicTable.addView(inflatedRow, 0);
}
我使用的不是“查看充气行=新建充气行(this)”,而是“查看充气行=充气行(build)(this)”。这是为自定义控件编写的文档,我也需要为合并的控件组编写。因此,我在一定程度上犯了错
@Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
或者(不知道这是否会继续得到支持:
@Click
void createNewRow() {
log.info("clicked");
/*View inflatedRow = InflatedRow_.build(this);*/
InflatedRow_ inflatedRow = new InflatedRow_(this);
inflatedRow.onFinishInflate();
dynamicTable.addView(inflatedRow, 0);
}
膨胀视图时不要使用带注释的类,并确保调用膨胀视图的构建方法
@Click
void createNewRow() {
log.info("clicked");
InflatedRow inflatedRow = new InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
膨胀视图时不要使用带注释的类,并确保调用膨胀视图的构建方法
@Click
void createNewRow() {
log.info("clicked");
InflatedRow inflatedRow = new InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
膨胀视图时不要使用带注释的类,并确保调用膨胀视图的构建方法
@Click
void createNewRow() {
log.info("clicked");
InflatedRow inflatedRow = new InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
膨胀视图时不要使用带注释的类,并确保调用膨胀视图的构建方法
@Click
void createNewRow() {
log.info("clicked");
InflatedRow inflatedRow = new InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
更新#1:似乎我需要调用shadow/generated class.build()方法,而不仅仅是构造它。例如,我使用View-inflatedRow=new-inflatedRow(this)而不是View-inflatedRow=inflatedRow.build(this)#'。我需要搜索文档,看看为什么我错过了这个,然后我会更新OP。但是,继续!更新#1:似乎我需要调用shadow/generated class.build()方法,而不仅仅是构造它。例如,我使用“View inflatedRow=new inflatedRow”(this);”而不是“View inflatedRow=inflatedRow”.build(this)#'。我需要搜索文档,看看为什么我错过了这个,然后我会更新OP。但是,继续!更新#1:似乎我需要调用shadow/generated class.build()方法,而不仅仅是构造它。例如,我使用“View inflatedRow=new inflatedRow”(this);”而不是“View inflatedRow=inflatedRow”.build(this)#'。我需要搜索文档,看看为什么我错过了这个,然后我会更新OP。但是,继续!更新#1:似乎我需要调用shadow/generated class.build()方法,而不仅仅是构造它。例如,我使用“View inflatedRow=new inflatedRow”(this);”而不是“View inflatedRow=inflatedRow”.build(this)'。我需要搜索文档,看看为什么我错过了这个,然后我会更新OP。但是,这应该是一个进步!这应该被标记为正确答案。关键是使用生成的类,在末尾加下划线和build方法。如果我错了,请纠正我,但是.build()是静态的>没有新操作符。'InflatedRow InflatedRow=InflatedRow_uu.build(这个)“这应该被标记为正确答案。关键是使用生成的类,并在末尾加下划线和build方法。如果我错了,请纠正我,但是.build()是静态的>没有新的运算符。'InflatedRow InflatedRow=InflatedRow_u2;.build(此)“这应该被标记为正确答案。关键是使用生成的类,并在末尾加下划线和build方法。如果我错了,请纠正我,但是.build()是静态的>没有新的运算符。'InflatedRow InflatedRow=InflatedRow_u2;.build(此)“这应该被标记为正确答案。关键是使用生成的类,并在末尾加下划线和build方法。如果我错了,请纠正我,但是.build()是静态的>没有新的运算符。'InflatedRow InflatedRow=InflatedRow_uuz.build(This);”