我開發一個應用程序,我動態填充父容器LinearLayout
蒙山許多其他LinearLayout
的孩子,這些孩子走了許多ImageButton
填充中的每一個,它基本上是這樣的:的Android - ImageButton的onClick事件不火
的XML代碼:
<ScrollView
android:layout_height="match_parent"
android:layout_width="fill_parent">
<LinearLayout
android:id="@+id/phasesContainer" (parent container)
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
和Java代碼:
for (PhaseActor pa : ph.get_actors()) {
if (pa.get_prospective() != Phase.PROGRAM)
continue;
ImageView phaseActor = new ImageView(context);
phaseActor.setImageResource((int) getActorFromMemory(
pa.get_actroId()).get_iconId());
phaseActor.setMaxHeight(30);
phaseActor.setMaxWidth(30);
phaseActor.setTag(pa.get_id());
phaseActor.setBackgroundResource(android.R.color.transparent);
phaseActor.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
editPhaseActorClick(Integer.getInteger(v.getTag()
.toString()));
}
});
// This container is the child (LinearOut) container
container.addView(phaseActor, imageLayout); }
當我點擊ImageView它不會做任何事情..功能不會觸發!