main.xml文件内容:
<Button
android:id="@+id/btn_dialog2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to display a progress dialog"
android:onClick="onClick"/>
MainActivity.java文件内容:
public void onclick(View v){
final ProgressDialog dialog=ProgressDialog.show(
this,"Doing something","Please wait...",true);
new Thread(new Runnable(){
public void run(){
try{
Thread.sleep(5000);
dialog.dismiss();
}
catch (InterruptedException e){
e.printStackTrace();
}
}
}).start();
}
启动程序后,安卓模拟器界面显示了一个按钮,但是我一点击报错如下:
E/AndroidRuntime(1754): java.lang.IllegalStateException: Could not find a method onClick(View)
in the activity class com.godlovesoccer.progressdialog.MainActivity for onClick handler on view
class android.widget.Button with id 'btn_dialog2'
我用的是Eclipse luna版,然后sdk是android4.2,求高手赐教!谢谢了!要不然我这买的书没法学下去了