using common Layout and its event in all activities

后端 未结 5 1397
你的背包
你的背包 2021-01-16 11:10

I have one common layout that has four button at top bar and i am using this layout in all activities by including that common layout in all activities layout by

5条回答
  •  攒了一身酷
    2021-01-16 11:37

    1. Define a header layout with 4 buttons and define android:onClick attributes inside xml layout for e.g. android:onClick="btnHomeClick", android:onClick="btnSearchClick"....etc.

    2. Define an Abstract class by extending Activity and implement all these click method:

      public void btnHomeClick(View v) {
      }
      
      public void btnSearchClick(View v)
      {
      }
      
    3. include that header layout by tag in your xml layout files. Now extends the above activity class in your every activity class.

    4. this way you just has to define a click event for once.

提交回复
热议问题