Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

java - Display contents of an array in a listview

Im making a project where the list items are contents with multiple attributes (username and passoword). I want to make the listview only display the usernames and once the username is clicked it would show the users password in a toast message. Im new to programming so i would need a few hints.

I managed to make the class and add 2 users to the array list. Any ideas on how i could make the listview only display the usernames and then the password once the username is clicked?

Thanks in advance :)

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    
        static class user {
            public String username;
            public String password;


        public user(String name, String pass) {
            username = name;
            password = pass;
            List<user> userList = new ArrayList<>();
            userList.add(new user("Tom", "Hello123"));
            userList.add(new user("Jack", "Hell1"));


        }


    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So, it might look like just adding a if statement and depending on what you are useing as a check box, then you could edit accordingly.

if(username == "Tom" ){
     Toast.makeText(this, "Your password is: Hello123", LENGTH_LONG);
} else if (username == "Jack"){
     Toast.makeText(this, "Your password is: Hell1", LENGTH_LONG);
} else {
     Toast.makeText(this, "Invalid or error found", LENGTH_LONG);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...