I have a class compositionJSON. The class has a method calls makeJSONObject, that creates a JSON-Object and put stuff in it. Here is the code of the class.
p
Thanks @Chris Handy! I created a JSONObjectVariable and assign it to the makeJSONObject. Here is my final code:
saveCompo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setName();
createJSONFolder();
CompositionJso compositionJso = new CompositionJso();
JSONObject obj;
obj = compositionJso.makeJSONObject(compoTitle, compoDesc, imgPaths, imageViewPaths);
MyCompositionsListActivity.buildList();
try {
Writer output;
File file = new File("storage/sdcard/MyIdea/MyCompositions/" + compoTitle + ".json");
output = new BufferedWriter(new FileWriter(file));
output.write(obj.toString());
output.close();
Toast.makeText(getApplicationContext(), "Composition saved", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
finish();
}
});