我正在使用我正在编写的android编程书中的一个例子.本练习的重点是,当我单击"关于"按钮时,应该启动一个新活动并显示一些文本.由于某些原因,即使文本显示在我的IDE中的图形布局中,文本也没有显示出来.我正在使用我的手机作为模拟器,而我的手机正在运行Android 4.0.3.我正在使用eclipse.这是我的代码:
主要活动:
package org.example.sodoku;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class Sudoku extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View continueButton= findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton= findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton= findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton= findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
} …Run Code Online (Sandbox Code Playgroud)