I am new to programming. Please tell me how to do something like a password.

The user must enter a specific word and the activation will continue. I can not figure out how this can be implemented.

Closed due to the fact that the issue is too general for the participants Yuriy SPb , Vladimir Martyanov , Saidolim , Grundy , insolor 10 Apr '16 at 19:21 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • At some point, display the unclosed (cancalabe = false) dialog. - Yuriy SPb
  • I do not understand how to programmatically set a string, and if it does not correspond to a specific value, then something like "try again" is displayed. It is advisable not using dialogue. - larin
  • Enter the string can only user. So you need an input field and claudia. And you can block the activation dialogue. - Yuriy SPb

1 answer 1

res / values ​​/ strings.xml :

<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">MyAndroidApp</string> <string name="lblPassword">Enter Your Password :</string> <string name="btn_submit">Submit</string> </resources> 

res / layout / main.xml :

 <TextView android:id="@+id/lblPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/lblPassword" android:textAppearance="?android:attr/textAppearanceLarge" /> <EditText android:id="@+id/txtPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" > <requestFocus /> </EditText> <Button android:id="@+id/btnSubmit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btn_submit" /> 

Code :

 package com.mkyong.android; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MyAndroidAppActivity extends Activity { private EditText password; private Button btnSubmit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addListenerOnButton(); } public void addListenerOnButton() { password = (EditText) findViewById(R.id.txtPassword); btnSubmit = (Button) findViewById(R.id.btnSubmit); btnSubmit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MyAndroidAppActivity.this, password.getText(), Toast.LENGTH_SHORT).show(); } }); } } 

Source of


Here is a lesson in creating a window with an entrance when opening an application.

In general, just use Google - there are plenty of examples .