如果Texboxt =" "
nextActivity.show
其他msg ="抱歉!"
任何人都可以帮助并告诉我如何在Android eclipse中创建这个吗?
我这里有代码,但我不知道如何解决这个问题。
private EditText inputtxt;
private Button btnNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_g1);
inputtxt = (EditText) findViewById(R.id.editText1);
btnNext.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View ContentView) {
// TODO Auto-generated method stub
String name;
name=inputtxt.getText().toString();
if (name.contentEquals("Accounting"))
{
Intent myIntent = new Intent (ContentView.getContext(), NextActivity.class);
startActivityForResult(myIntent, 0);
}
else
{ Toast.makeText(getBaseContext(), "Sorry, wrong answer. Try Again!", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.g1, menu);
return true;
}
`
答案 0 :(得分:0)
更改为:
if (name.length()==0)
{
Intent myIntent = new Intent (ContentView.getContext(), NextActivity.class);
startActivityForResult(myIntent, 0);
}
else
{
Toast.makeText(getBaseContext(), "Sorry, wrong answer. Try Again!", Toast.LENGTH_SHORT).show();
}
答案 1 :(得分:0)
将您的字符串与此
进行比较 if(name.equalsIgnoreCase("Accounting"))
答案 2 :(得分:0)
if(name.equalsIgnoreCase("Accounting"))
而不是
if (name.contentEquals("Accounting"))
答案 3 :(得分:0)
更新您的代码,如下所示可能有效..
private EditText inputtxt;
private Button btnNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_g1);
inputtxt = (EditText) findViewById(R.id.editText1);
btnNext.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View ContentView) {
// TODO Auto-generated method stub
String name;
name=inputtxt.getText().toString();
if (name.equalsIgnoreCase("Accounting"))
{
Intent myIntent = new Intent (QuizActivity.this, NextActivity.class);
startActivity(myIntent);
}
else
{ Toast.makeText(getApplicationContext(), "Sorry, wrong answer. Try Again!", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.g1, menu);
return true;
}
答案 4 :(得分:0)
使用startActivityForResult(intent)
将打开一个新活动,之前的活动将等待新活动的结果。使用Bundle在活动之间共享消息,并使用startActivity(intent)
而不是startActivityForResult(intent)
答案 5 :(得分:0)
if (value.equals("")) {
Log.e("value equal to zero", value);
} else {
Log.e(value, "value not equal to zero");
startActivity(new Intent(Registernew.this, next.class));
finish();
}