这是我的代码,我不知道我做错了什么。但它不起作用!理想情况下,我想要的是如果所有文本视图都是空的,它应该“请填写详细信息”或“保存”,但它总是如何“保存”
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
EditText et1;
EditText et2;
EditText et3;
EditText et4;
EditText et5;
Button b;
FileOutputStream fos1;
FileOutputStream fos2;
FileOutputStream fos3;
FileOutputStream fos4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText) findViewById(R.id.editText1);
et2=(EditText) findViewById(R.id.editText2);
et3=(EditText) findViewById(R.id.editText3);
et4=(EditText) findViewById(R.id.editText4);
et5=(EditText) findViewById(R.id.editText5);
b=(Button) findViewById(R.id.button1);
b.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String password=et1.getText().toString();
String confirmPassword=et2.getText().toString();
String secQues=et3.getText().toString();
String secAns=et4.getText().toString();
String hint=et5.getText().toString();
if(password!=null && confirmPassword!=null && secQues!=null && secAns!=null && hint!=null)
{
Toast.makeText(MainActivity.this, "saved", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "Please fill all the details.", Toast.LENGTH_SHORT).show();
}
}
}