我正在努力从我正在做的示例应用程序中获取最终结果。我通过在stackoverflow上获得人们的帮助解决了我的许多问题,但我仍然无法解决这个问题!有人可以编辑这段代码,所以我第二次使用它时没有收到错误“MainActivity类型已定义”吗?我可以看到为什么这是错误的格式,但我不知道如何解决它!这是代码:
package com.example.progressdialog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
public class mainactivity2 {
}
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
progress = new ProgressDialog(this);
}
public void open(View view){
progress.setMessage("Progressing!");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(false);
progress.show();
final int totalProgressTime = 100;
final Thread t = new Thread(){
@Override
public void run(){
int jumpTime = 0;
while(jumpTime < totalProgressTime){
try {
sleep(500);
jumpTime += 1;
progress.setProgress(jumpTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
Button next = (Button) findViewById(R.id.button2);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), Activity2.class);
startActivityForResult(myIntent, 0);
}
});
}
}
答案 0 :(得分:0)
您要定义MainActivity
两次。而且由于某种原因,你的第一个MainActivity中有一个内部mainactivity2类。
答案 1 :(得分:0)
public class MainActivity extends Activity {
/** Called when the activity is first created. */
public class MainActivity extends Activity {
???您正尝试两次定义MainActivity。你看到了吗?