当前位置: 代码迷 >> Android >> 初学者!onClick(DialogInterface dialog, int which){}和onClick(View v){}不同
  详细解决方案

初学者!onClick(DialogInterface dialog, int which){}和onClick(View v){}不同

热度:391   发布时间:2016-05-01 17:45:35.0
菜鸟求助!onClick(DialogInterface dialog, int which){}和onClick(View v){}不同
我在重写onclicklistener方法的时候eclipse给我自动生成了onClick(DialogInterface dialog, int which){}方法,可是我用setOnClickListener()时模拟器运行错误,我看视频上用的是onClick(View v){}方法,可是我的sdk1.6并没有这个方法啊!哪个大虾给指点下吧!
附代码:
public class Activity01 extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  TextView myTextView = (TextView)findViewById(R.id.myTextView);
  Button myButton = (Button)findViewById(R.id.myButton);
  myTextView.setText("我的第一个TextView");
  myButton.setText("我的第一个Button");
  myButton.setOnClickListener((android.view.View.OnClickListener) new myButtonListener());
  }
  class myButtonListener implements OnClickListener{

public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(Activity01.this, Activity02.class);
}
 
  }
}

------解决方案--------------------
button的onClick事件为:button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener(){
public void onClick(View view){

}
});
导入包为:import android.view.View.OnClickListener;
你别整错了
  相关解决方案