0

如果文本框 = ""

nextActivity.show

else msg = "对不起!"

任何人都可以帮助并告诉我如何在 Android eclipse java 中制作这个吗?

我这里有一个代码,但我不知道如何更正。

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;        
    }

`

4

6 回答 6

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();
  }     
于 2013-09-28T05:54:48.947 回答
0

将您的字符串与此进行比较

   if(name.equalsIgnoreCase("Accounting"))
于 2013-09-28T05:55:41.137 回答
0
if(name.equalsIgnoreCase("Accounting"))

代替

if (name.contentEquals("Accounting"))
于 2013-09-28T05:56:30.283 回答
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;        
    }
于 2013-09-28T05:57:54.933 回答
0

使用startActivityForResult(intent)将打开一个新活动,并且前一个活动等待新活动的结果。使用 Bundle 在活动之间共享消息并使用 startActivity(intent)而不是startActivityForResult(intent)

于 2013-09-28T05:59:05.867 回答
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();
    }
于 2013-09-28T06:02:40.360 回答