好的,所以在我把if语句后我在关闭的brakers上得到了这个错误 包com.example.mohhmed.king;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
public class l1 extends Activity {
ImageButton ans;
TextView text;
boolean check(){
if (text.getText()=="")
return true;
else
return false;
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.l1);
ans = (ImageButton) findViewById(R.id.imageButton);
text = (TextView) findViewById(R.id.textView);
ans.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(check()==true){
Intent myIntent = new Intent(v.getContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
}
else
text.setText("اجابة خاطئة");
}`enter code here`
);<----- here
}<----- here
}<----- here
}
答案 0 :(得分:1)
更改
boolean check(){
if (text.getText()=="")
return true;
else
return false;
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.l1);
ans = (ImageButton) findViewById(R.id.imageButton);
text = (TextView) findViewById(R.id.textView);
ans.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(check()==true){
Intent myIntent = new Intent(v.getContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
}
else
text.setText("اجابة خاطئة");
}`enter code here`
);<----- here
}<----- here
}<----- here
应该是
boolean check(){
return "".equals(text.getText()))
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.l1);
ans = (ImageButton) findViewById(R.id.imageButton);
text = (TextView) findViewById(R.id.textView);
ans.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(check()){
Intent myIntent = new Intent(v.getContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
} else {
text.setText("اجابة خاطئة");
}
});
}