0

我认为如果我在 android 上的所有屏幕都有一个基类,那将是必要的。然后我不必重新输入相同的内容,....但是当我用 cBase(我的基类)替换 Activty 时它崩溃了

基类

public class cBase extends Activity{

  public void onCreate(Bundle savedInstanceState) {

  }

}

我的课崩溃了

public class TellaFortuneActivity extends cBase implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // add the add
    // Create the adView
    AdView adView;
    adView = new AdView(this, AdSize.BANNER, "a14e10cb6b18825");

    // Lookup your LinearLayout assuming it’s been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());



    // add listeners
    View mAbout = findViewById(R.id.bio);
    mAbout.setOnClickListener(this);

    View mHistory = findViewById(R.id.history);
    mHistory.setOnClickListener(this);

    View mYesNo = findViewById(R.id.butyesno);
    mYesNo.setOnClickListener(this);

    View mSocial = findViewById(R.id.socialgame);
    mSocial.setOnClickListener(this);

    View mWheel = findViewById(R.id.wheelgame);
    mWheel.setOnClickListener(this);

    View mChat = findViewById(R.id.chat);
    mChat.setOnClickListener(this);

    View mTest = findViewById(R.id.test);
    mTest.setOnClickListener(this);       

}

public void onClick(View v) {
    Intent i;
    switch(v.getId())
    {

    case R.id.bio:
        // check data first

            i = new Intent(this, cBio2.class);
            startActivity(i);

        break;

    case R.id.history:
            i = new Intent(this, cHistory.class);
            startActivity(i);
        break;

    case R.id.chat: 
        i = new Intent(this, cChat.class);
        startActivity(i);
        break;      

    case R.id.wheelgame:    
        i = new Intent(this,cYesNoCardDeck.class);
        startActivity(i);           
        break;                  

    case R.id.socialgame:   
        i = new Intent(this,cSocialGame.class);
        startActivity(i); 
        break;              

    case R.id.butyesno: 
        i = new Intent(this, cYesNoDirections.class);
        startActivity(i); 
        break;     

    case R.id.test:
        i = new Intent(this, cYesNoShuffle.class);
        startActivity(i); 
        break;  


       } // end else

   } // end function
} // end class
4

1 回答 1

2

cBase您应该使用@Override该方法,并且onCreate(Bundle savedInstanceState)它还必须调用super.onCreate(Bundle savedInstanceState)

于 2012-06-04T22:58:19.937 回答