0

我正在开发一个 Android 项目。每个页面都有一个页脚(设置,我的个人资料,后退按钮)......我想在 BaseView 中编写这个功能(页脚按钮单击功能),这样我就可以从我的所有其他活动中扩展这个 BaseView,而且我也不需要调用每个页面都具有相同的功能。我该如何实现它。

4

3 回答 3

0

尝试自定义布局:

   public class Footer extends LinearLayout {

public Context context;
public ImageButton btnNearest, btnPin, btnRegister;

public Footer(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    if (!isInEditMode())
        init();
}

private void init() {
    LayoutInflater.from(context).inflate(R.layout.footer, this, true);
    btnNearest = (ImageButton) findViewById(R.id.btn_nearest_aed);
    btnPin = (ImageButton) findViewById(R.id.btn_pin_aed);
    btnRegister = (ImageButton) findViewById(R.id.btn_register_aed);
}

}

这适用于所有 xml:

     <com.pkg.Footer
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    />
于 2013-09-13T12:47:06.080 回答
0

我认为你需要创建一个 BaseActivity 像

abstract public class BaseActivity extends FragmentActivity {

}

和所有其他活动扩展 BaseActivity

这是一个小例子。它使用操作栏,您必须将其更改为按钮。

于 2013-09-13T12:47:52.143 回答
0

您可以在 OnClickListenerType 的基类中创建一个变量,并将您的公共代码放在那里。然后,您可以为子类中的每个按钮设置 onclick 侦听器。

在您的基类中:

   OnClickListener listener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    };

在您的孩子班:

   button.setOnClickListener(listener);
于 2013-09-13T12:44:36.290 回答