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.
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.
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 .
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(); } }); } }
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 .
Source: https://ru.stackoverflow.com/questions/510435/
All Articles