I add a listview via Java into @+id/View01. For some reason the items in the listview don't accept clicks. Does anybody have ideas about possible causes?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:background="@color/light_blue"
>
<Button android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<AbsoluteLayout
android:id="@+id/Layout01"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_below="@+id/Button01"
android:layout_above="@+id/Button02"
android:layout_height="fill_parent">
<View android:id="@+id/View01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<ListView android:id="@+id/ListView02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"/>
</AbsoluteLayout>
<Button android:text="@+id/Button02"
android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>
If I change my code to the following the clicks work but the layout doesn't look the way I want.:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
android:background="@color/light_blue"
>
<Button android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<View android:id="@+id/View01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Button01"
android:gravity="center_horizontal"
/>
<ListView android:id="@+id/ListView02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/View01"
android:gravity="center_horizontal"
android:layout_above="@+id/Button02"/>
<Button android:text="@+id/Button02"
android:id="@+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>
One of the functions involved:
protected void initiateExtraView(FillInput fillInput){
View extraView = fillInput.getExtraView();
ViewGroup parent = (ViewGroup) extraView.getParent();
int index = parent.indexOfChild(extraView);
parent.removeView(extraView);
extraView = fillInput.getLayoutInflater().inflate(
R.layout.extrabuttonlistview,
parent,
false);
parent.addView(extraView, index);
fillInput.setExtraView(extraView);
ListView extraButtonView = (ListView) extraView;
fillInput.setExtraButtonListView(extraButtonView);
ListAdapter adapter = new ExtraButtonAdapter(fillInput, this);
fillInput.getExtraButtonListView().setAdapter(adapter);
}
The function in the ExtraButtonAdapter that create the particular view that doesn't accept clicks:
private View getNewForm(int position, View convertView,
ViewGroup parent) {
View view = mInflater.inflate(
R.layout.new_form_button,
parent,
false);
View.OnClickListener listener = new View.OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "Click on NewForm");
}
};
view.setOnClickListener(listener);
setNewFormView(view);
return view;
}
R.layout.extrabuttonlistview:
<?xml version="1.0" encoding="UTF-8"?>
<ListView android:id="@+id/ListView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center_horizontal"
android:layout_above="@+id/Button02"/>