我有一个关于我是否可以在同一个活动中设置内容视图两次的一般性android问题。我会在这里发布代码,但它非常混乱。我正在为我的排行榜和成就使用一种名为swarm的服务,所以很多都只是混杂在一起。但问题是我的按钮叫做板底。有时当我点击按钮时,它只是决定不注册点击并关闭当前活动。
public class WholettheballoutActivity extends SwarmActivity {
GLView view;
public GLRenderer renderer;
public static int level = 4;
public LinearLayout parentView;
public Handler handle;
public SwarmLeaderboard leaderboard;
public Map achievements;
GotLeaderboardCB callback = new GotLeaderboardCB() {
public void gotLeaderboard(SwarmLeaderboard leaderboard1) {
// Save the leaderboard for later use...
leaderboard = leaderboard1;
}
};
GotAchievementsMapCB callback2 = new GotAchievementsMapCB() {
public void gotMap(Map<Integer, SwarmAchievement> achievements1) {
// Store the map of achievements somewhere to be used later.
achievements = achievements1;
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.score);
view = (GLView) findViewById(R.id.mySurfaceView);
parentView = (LinearLayout) findViewById(R.id.parent);
handle = new Handler(new Handler.Callback(){
@Override
public boolean handleMessage(Message msg){
// message is handled by the UI thread
if (!Swarm.isLoggedIn()) {
Swarm.init(WholettheballoutActivity.this, 240, "66e982c9795ca5871cc48b0dd34cdabe");
}
TextView tv = (TextView) findViewById(R.id.textView2);
String temp = msg.obj.toString();
tv.setText(temp);
if (renderer.time==0) {
SwarmAchievement.getAchievementsMap(callback2);
// Make sure that we have our achievements map.
if (level < 11) {
if (achievements != null) {
// Grab the achievement from our map.
SwarmAchievement achievement = (SwarmAchievement) achievements.get(592 + level);
// No need to unlock more than once...
if (achievement != null && achievement.unlocked == false) {
achievement.unlock();
}
}
}
WholettheballoutActivity.level+=1;
//NewLevelActivity.time= 30;
Intent newLevel = new Intent(WholettheballoutActivity.this,NewLevelActivity.class);
startActivityForResult(newLevel, 1);
renderer.time= (level * 10);
}
if (view.renderer.B.numBalls == 0) {
SwarmAchievement.getAchievementsMap(callback2);
if (view.renderer.points > 10000) {
if (achievements != null) {
// Grab the achievement from our map.
SwarmAchievement achievement = (SwarmAchievement) achievements.get(603);
// No need to unlock more than once...
if (achievement != null && achievement.unlocked == false) {
achievement.unlock();
}
}
if (view.renderer.points > 25000) {
if (achievements != null) {
// Grab the achievement from our map.
SwarmAchievement achievement = (SwarmAchievement) achievements.get(604);
// No need to unlock more than once...
if (achievement != null && achievement.unlocked == false) {
achievement.unlock();
}
}
if (view.renderer.points > 50000) {
if (achievements != null) {
// Grab the achievement from our map.
SwarmAchievement achievement = (SwarmAchievement) achievements.get(605);
// No need to unlock more than once...
if (achievement != null && achievement.unlocked == false) {
achievement.unlock();
}
}
if (view.renderer.points > 100000) {
if (achievements != null) {
// Grab the achievement from our map.
SwarmAchievement achievement = (SwarmAchievement) achievements.get(606);
// No need to unlock more than once...
if (achievement != null && achievement.unlocked == false) {
achievement.unlock();
}
}
}
}
}
}
level = 1;
setContentView(R.layout.score_page);
final Button play = (Button) findViewById(R.id.button1);
final Button boards = (Button) findViewById(R.id.boards);
TextView score = (TextView) findViewById(R.id.textView2);
score.append("Score: " + view.renderer.points);
play.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
WholettheballoutActivity.this.finish();
}
});
boards.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SwarmLeaderboard.getLeaderboardById(193, callback);
// First, make sure that we have our leaderboard.
if (!Swarm.isLoggedIn()) {
Swarm.init(WholettheballoutActivity.this, 240, "66e982c9795ca5871cc48b0dd34cdabe");
}
if (leaderboard != null) {
// Submit our score
leaderboard.submitScore(view.renderer.points);
}
if (leaderboard != null) {
leaderboard.showLeaderboard();
}
WholettheballoutActivity.this.finish();
}
});
}
return true;
}
});
renderer = new GLRenderer(this, parentView, handle);
view.setRenderer(renderer);
view.renderer = renderer;
// You can use a FrameLayout to hold the surface view
/* FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(view);
// Then create a layout to hold everything, for example a RelativeLayout
RelativeLayout relativeLayout= new RelativeLayout(this);
relativeLayout.addView(frameLayout);
setContentView(relativeLayout);*/
}