У меня есть заголовок, который я должен включить в несколько действий, и я хочу обработать OnClickListener для кнопок из той же самой активности. Я следовал этому вопросу Button Onclick Listener in included layoutsта же компоновка и те же самые onclicklisteners для нескольких действий
но в моем случае это не работает. я есть common_header.xml как:
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/layout_top_bar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:clickable="true"
android:background="@color/titlebarBackground"
>
<ImageButton
android:id="@+id/btn_menu"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="menu"
android:background="@drawable/borderless_button_unselected"
android:src="@drawable/menu"
/>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btn_account"
android:textColor="@color/titlebarForeground"
android:textSize="16sp"
android:text="@string/signin"
android:background="@drawable/transparent_signin_selector"
/>
<ImageButton
android:id="@+id/btn_account"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="menu"
android:background="@drawable/borderless_button_unselected"
android:src="@drawable/account"
/>
</RelativeLayout>
<ListView
android:id="@+id/listview_account"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/menuDivider"
android:dividerHeight="1px"
android:layout_below="@+id/layout_top_bar"
android:visibility="gone"
>
</ListView>
<ListView
android:id="@+id/listview_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/menuDivider"
android:dividerHeight="1px"
android:layout_below="@+id/layout_top_bar"
android:visibility="gone"
>
</ListView>
</merge>
и в другом макете я использовал это следующим образом:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/appBackground" >
<com.example.myApp.MenuView
android:id="@+id/common_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
.../>
<Button
.../>
</RelativeLayout>
мой класс MenuView является:
public class MenuView extends RelativeLayout {
private LayoutInflater inflater;
public MenuView(Context context, AttributeSet attrs) {
super(context, attrs);
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.common_header, this, true);
}
}
он оленья кожа показать мне какой-либо ошибка при запуске приложения, но common_header не объединен в моем макете. Я не мог понять, где моя ошибка. Пожалуйста, помогите.
thanx for ur help ... Я попытался изменить тег на , но проблема такая же. Он не показывает мне никаких ошибок, но не сливается. И я попробовал второй вариант, используя тег в common_header.xml и в другом макете xml, но проблема такая же. –
Dharma
try inflater.inflate (R.layout.common_header, это); вместо inflater.inflate (R.layout.common_header, это, правда); –
Я пробовал это .. но проблема в том же брате .... – Dharma