Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize easy login and registration with Android

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "Android how to achieve easy login registration", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Android how to achieve easy login registration" this article.

Activity_login

LoginActivity

Package com.jld.exam;import android.content.Intent;import android.os.Bundle;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class LoginActivity extends AppCompatActivity {EditText ed_username;EditText ed_password;Button bu_login;Button bu_register;String username;String password;@Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_login); ed_username = findViewById (R.id.ed_username) Ed_password = findViewById (R.id.ed_password); bu_login = findViewById (R.id.bu_login); bu_register = findViewById (R.id.bu_register); / / login button listens to bu_login.setOnClickListener (v-> {username = ed_username.getText () .toString (); password = ed_password.getText () .toString ()) / the simple logic of login if (username.equals (")) {Toast.makeText (LoginActivity.this," Please enter user name ", Toast.LENGTH_SHORT) .show ();} else if (password.equals (")) {Toast.makeText (LoginActivity.this, "Please enter password", Toast.LENGTH_SHORT) .show () } else if (! username.equals ("root") | |! password.equals ("123456") {Toast.makeText (LoginActivity.this, "wrong username or password", Toast.LENGTH_SHORT). Show ();} else {Intent intent = new Intent (LoginActivity.this, MainActivity.class); startActivity (intent);}}); / / Registration button listens on bu_register.setOnClickListener (v-> {Intent intent = new Intent (LoginActivity.this, RegisterActivity.class); startActivity (intent);});}}

Activity_main

MainActivity

Package com.jld.exam;import android.graphics.Color;import android.os.Bundle;import android.widget.LinearLayout;import androidx.appcompat.app.AppCompatActivity;import androidx.recyclerview.widget.GridLayoutManager;import androidx.recyclerview.widget.RecyclerView;public class MainActivity extends AppCompatActivity {RecyclerViewAdapter recyclerViewAdapter Private final int [] icno = {R.drawable.clock, R.drawable.signal, R.drawable.box, R.drawable.second, R.drawable.elephone, R.drawable.ff, R.drawable.notebook, R.drawable.mark, R.drawable.yx. Shop, R.drawable.theme, R.drawable.xl,} Private final String [] name = {"clock", "signal", "treasure chest", "seconds", "Elephant", "FF", "notepad", "Bookmark", "impression", "Store", "theme", "Thunderbolt"}; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); / / GridLayoutManagerGridLayoutManager gridLayoutManager = new GridLayoutManager (MainActivity.this, 3) / / create recyclerviewRecyclerView recyclerView = findViewById (R.id.recycler); / / set layout manager recyclerView.setLayoutManager (gridLayoutManager); / / create adapter recyclerViewAdapter = new RecyclerViewAdapter (icno, name); recyclerView.setAdapter (recyclerViewAdapter); / / set adapter}}

Activity_register

RegisterActivity

Package com.jld.exam;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;public class RegisterActivity extends AppCompatActivity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_register);}}

Recyc_item

RecyclerViewAdapter

Package com.jld.exam;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.TextView;import androidx.annotation.NonNull;import androidx.recyclerview.widget.RecyclerView;public class RecyclerViewAdapter extends RecyclerView.Adapter {private final int [] icno;private final String [] desc;public RecyclerViewAdapter (int [] icno, String [] desc) {this.icno = icno;this.desc = desc } @ NonNull@Overridepublic ViewHolder onCreateViewHolder (@ NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from (parent.getContext ()) .propagate (R.layout.recyc_item, parent, false); return new ViewHolder (view);} @ Overridepublic void onBindViewHolder (@ NonNull ViewHolder holder, int position) {holder.imageView.setImageResource (position]); holder.textView.setText (position);} @ Overridepublic int getItemCount () {return icno.length;} / / ViewHolderpublic static class ViewHolder extends RecyclerView.ViewHolder {View item;ImageView imageView;TextView textView Public ViewHolder (@ NonNull View itemView) {super (itemView); item = itemView;imageView = itemView.findViewById (R.id.iv_image); textView = itemView.findViewById (R.id.tv_desc);} these are all the contents of the article "how to achieve easy login and registration in Android". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report