我正在验证登录页面中的两个编辑文本字段,而我的想法几乎没有变化。如果用户在不输入文本的情况下离开字段e1并转到e2,我需要在此字段上方显示textview。任何帮助表示赞赏。
这是我的代码:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
;
public class LoginActivity extends Activity {
EditText usernameText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginpage);
Button login = (Button) findViewById(R.id.loghomebutton);
Button newuser = (Button) findViewById(R.id.lognewuserbutton);
EditText usernameText = (EditText)this.findViewById(R.id.emaileditlog);
EditText passwordText = (EditText)this.findViewById(R.id.pwdeditlog);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(v.getContext(),
SettingsActivity.class);
startActivityForResult(myIntent, 0);
overridePendingTransition(R.anim.fadeout, 0);
}
});
newuser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(v.getContext(),
RegisterActivity.class);
startActivityForResult(myIntent, 1);
overridePendingTransition(R.anim.fadeout, 0);
}
});
}
}
答案 0 :(得分:1)
在XML中在edittext上面添加一个textview .. set textviews android:visibility="GONE"
然后在java代码中执行此操作..
if(editText.getText.toString().equals(" "))
{
TextView t = findViewById(.......)
t.setVisibility(View.VISIBLE);
t.setText("..............");
}
答案 1 :(得分:0)
在xml布局中,定义textview,根据需要放置,然后使用
android:visibility="gone"
并在您的代码中,在需要时
TextView errorTextView = (TextView) findViewById( R.id.error_view );
errorTextView.setVisibility( View.VISIBLE );
此致 斯特凡
答案 2 :(得分:0)
答案 3 :(得分:-1)
我在我的计算器应用程序中使用了这样的内容。我在Textbox中显示Alertdialog而不是显示错误消息
if(calc_txt_Prise.getEditableText().toString().trim().equals(""){
String dialog_message = "Please enter some Text";
AlertDialog.Builder invalid_input_dialog = new AlertDialog.Builder(Archive.this);
invalid_input_dialog.setTitle("Application name")
.setMessage(dialog_message)
.setCancelable(true)
.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(DATE_DIALOG_ID);
}
})
}