为什么总是提示我setOnClickListener((OnClickListener)this) 出错
mportandroid.content.Intent;importandroid.os.Bundle;importandroid.support.v4.app.Frag...
mport android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
public class MainActivity extends ActionBarActivity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Set up click listeners for all buttons
//View continueButton = this.findViewById(R.id.continue_button);
//continueButton.setOnClickListener((OnClickListener) this);
// View newButton = this.findViewById(R.id.new_button);
//newButton.setOnClickListener((OnClickListener) this);
findViewById(R.id.about_button).setOnClickListener(this);//删掉这句话就可以运行了
// View exitButton = this.findViewById(R.id.exit_button);
// exitButton.setOnClickListener((OnClickListener) this);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.about_button:
Intent i = new Intent(MainActivity.this,About.class);
startActivity(i);
break;
//More Buttons
}
} 展开
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
public class MainActivity extends ActionBarActivity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Set up click listeners for all buttons
//View continueButton = this.findViewById(R.id.continue_button);
//continueButton.setOnClickListener((OnClickListener) this);
// View newButton = this.findViewById(R.id.new_button);
//newButton.setOnClickListener((OnClickListener) this);
findViewById(R.id.about_button).setOnClickListener(this);//删掉这句话就可以运行了
// View exitButton = this.findViewById(R.id.exit_button);
// exitButton.setOnClickListener((OnClickListener) this);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.about_button:
Intent i = new Intent(MainActivity.this,About.class);
startActivity(i);
break;
//More Buttons
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询