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
273 views
in Technique[技术] by (71.8m points)

android - How to use the hashmap in DataModel

I am newbie to Android and I am working in an Android project. I want to implement a data model, using that model I want to perform the arithmetic operations using the Hash Map.

But I don't know how to implement it. And also I want to print the value in Text View. The project is like an Calculator.

ModelActivity

Create the getter and setter I don't know how to implement this

MainActivity

Using that Model I have to perform the operation like getting and setting the value using the Hash map.

This is my model class

public class Model {

    public Map<String, String> getSmap(String string, String str) {
        return Smap;
    }

    public Map<Integer, Integer> getImap() {
        return Imap;
    }

    public Map<String, Integer> getSImap() {
        return SImap;
    }

    public Map<Integer, String> getISmap(String jeeva, String s) {
        return ISmap;
    }

    private Map<String, String> Smap = new HashMap<>();
    private Map<Integer, Integer> Imap = new HashMap();

    private Map<String, Integer> SImap = new HashMap<>();
    private Map<Integer, String> ISmap = new HashMap<>();

    public Map<Integer, String> getISmap(String jeeva) {

        return ISmap;
    }
}

Using that model I want to perform the operations like add sub.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

For my understanding you want to know how to populate HashMaps. So first of all you should read this documentation: https://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html

Code:

Map<String, String> map = new HashMap<>();

// Add things to the map
map.put("key","value");

// Get values from map
String value = map.get("key");

In very generic terms with this you can start doing stuff :) but you should absolutely read the documentation and have a deep understanding regarding how a Map works and then decide which type of Map you need to fulfil your requirements.


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

...