1
I am with a following doubt, I am using a listview
with about 300 characters of a game, when clicking on a character he inserts some dice that is written in the config.properties
, all characters have descriptions, vocations and other different information.
The code is working properly, but my doubt is the way I’m entering the data will not make the code too heavy? There’s another way more correct?
Code:
Util.java.
public class Util {
public static String getProperty(String key, Context context) throws IOException {
Properties properties = new Properties();;
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open("config.properties");
properties.load(inputStream);
return properties.getProperty(key);
}
}
Ivysauractivity.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ivysaur);
//mToolbar = (Toolbar) findViewById(R.id.Toolname);
mToolbar = (TextView) findViewById(R.id.Toolname);
Number = (TextView) findViewById(R.id.Number);
Level = (TextView) findViewById(R.id.Level);
Valornpc = (TextView) findViewById(R.id.Valornpc);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
mToolbar.setText(bundle.getString("TituloPokemon"));
if (mToolbar.getText().toString().equalsIgnoreCase("Bulbasaur")) {
try {
Number.setText(Util.getProperty("Number",getApplicationContext()));
Level.setText(Util.getProperty("Level",getApplicationContext()));
Valornpc.setText(Util.getProperty("Valornpc",getApplicationContext()));
} catch (IOException e) {
e.printStackTrace();
}
}
else
if (mToolbar.getText().toString().equalsIgnoreCase("Venusaur")) {
try {
Number.setText(Util.getProperty("Number2",getApplicationContext()));
Level.setText(Util.getProperty("Level2",getApplicationContext()));
Valornpc.setText(Util.getProperty("Valornpc2",getApplicationContext()));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
config.properties
Number=Teste1
Level=240
Valornpc=28.000;
Number2=Teste2
Level2=540
Valornpc2=58.000;
Thanks in advance
Got it, how do I save . properties elsewhere but not locally?
– Erik Grupioni
You need a web server. You save the file to it and then access via HTTP or FTP from your source. Ex HTTP:
URL url = new URL("http://seuservidor.com.br/config.properties");
But that’s a matter for another question.– Zulian
Zulian, nice explanation. + 1
– viana