0

How to find an attribute name, rather than its value from a model in Android Java.

I've written an android method to scan the data from the view and to return it to the model (by Declared).

To detect the attribute identity, I've defined a tag in the view using a hard code string.

Now, when I want to rename the attribute in the model, I change the tag name in the code, using hard code.

But, I need to find attribute name from the model as dynamic, not from the hard code string.

for example in this model

public class CodeNameModel {
private Long Code;
private String Name;
public Long getCode() {
    return Code;
}
public void setCode(Long code) {
    Code = code;
}
public String getName() {
    return Name;
}
public void setName(String name) {
    Name = name;
}
}

and in the code

CodeNameModel codeNameModel = new CodeNameModel();
codeNameModel.setCode(3L);
codeNameModel.getCode();

I need the model to return "Code" and "Name" in the string value, not their value like 3. I mean, I need the attribute name in the string format for example a method to return "CODE" in string format when call getCodeName().

codeNameModel.getcode();

answer is 3;

I need below method

codeNameModel.getcodeName();

I need return "Code" in string format.

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
Ali Doran
  • 35
  • 9
  • Sorry but I don't understand your question. Can you maybe give a concrete example of what you want (instead of a description)? – Beko Oct 31 '20 at 14:03
  • It is very hard to understand this because of language issues, I suppose. Maybe writing down the question in your native language (Farsi, I think), and have it translated with google translate might make it clearer. Check it out: فکر می کنم درک این مسئله به دلیل مسائل زبان بسیار دشوار است. – Curiosa Globunznik Oct 31 '20 at 14:07

1 Answers1

0

I think this is what you mean. You want the code value as a string as far as I can understand, and here is how you can do it:

public String getCode() {
    return String.valueOf(Code);
}
Furkan Yurdakul
  • 1,843
  • 11
  • 25