1

I have a special Problem.

I'm loading a XML File from Web with different tags like <job_id>. These XML Data is written to a file named xmlInformations.xml. Every Information is loaded from file to a ArrayList<Hashmap<String,String>> named taskItems

public void setListTaskData(String filename) {

    XMLParser parser = new XMLParser();
    Document doc = parser.getDomElement(readFromFile(filename));

    NodeList nodeListTasks = doc.getElementsByTagName(KEY_TASK);

    for (int i = 0; i < nodeListTasks.getLength(); i++) {
        HashMap<String, String> map = new HashMap<>();
        Element e = (Element) nodeListTasks.item(i);

        map.put(KEY_TASK_UUID_OBJ, parser.getValue(e, KEY_TASK_UUID_OBJ));
        map.put(KEY_TASK_TITLE, parser.getValue(e, KEY_TASK_TITLE));
        map.put(KEY_TASK_INFO, parser.getValue(e, KEY_TASK_INFO));
        map.put(KEY_TASK_OBJECT, parser.getValue(e, KEY_TASK_OBJECT));
        map.put(KEY_TASK_LOCATION, parser.getValue(e, KEY_TASK_LOCATION));
        map.put(KEY_TASK_OBJECT_ID, parser.getValue(e, KEY_TASK_OBJECT_ID));
        map.put(KEY_TASK_OBJECT_SNR, parser.getValue(e, KEY_TASK_OBJECT_SNR));
        map.put(KEY_TASK_REGISTRATION_ID, parser.getValue(e, KEY_TASK_REGISTRATION_ID));
        map.put(KEY_TASK_TASKIMAGE, parser.getValue(e, KEY_TASK_TASKIMAGE));
        map.put(KEY_TASKIMAGE, parser.getValue(e, KEY_TASKIMAGE));
        map.put(KEY_TASK_HEADLINE, parser.getValue(e, KEY_TASK_HEADLINE));
        map.put(KEY_TASK_SUBJECT, parser.getValue(e, KEY_TASK_SUBJECT));
        map.put(KEY_TASK_ACTION, parser.getValue(e, KEY_TASK_ACTION));
        map.put(KEY_TASK_PRIORITY_COLOR, parser.getValue(e, KEY_TASK_PRIORITY_COLOR));
        map.put(KEY_TASK_STATUS, parser.getValue(e, KEY_TASK_STATUS));
        taskItems.add(map);
    }
}

They will displayed on a ListView. After i clicked on an Item, it starts a new Activity named SingleTaskActivity. This Activity gets the Informations by an IntentExtra from TaskListActivity.

It looks like:

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    //neue Oberflaeche starten
    Intent in = new Intent(this, SingleTaskList.class);;
    in.putExtra("taskItems", taskItems.get(position));

    startActivity(in);
}

The SingleTaskActivity displays now the Informations.

    super.onCreate(savedInstanceState);

    Intent i = getIntent();
    ListView lv = getListView();
    lv.setOnItemClickListener(this);
    Serializable xmlFileNames = i.getSerializableExtra("xmlFileNames");
    String filename = xmlFileNames.toString()+".kx_task";
    setListTaskData(filename);

    CustomAdapterTasks adapterTasks = new CustomAdapterTasks(this,taskItems);
    setListAdapter(adapterTasks);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

The User now can type something in an Edittext or take a Picture.

And here is the Problem:

When a User finishes his work and is clicking on the button "save" at the bottom, how can i save all these Informations into the File at the same position in that XML File?

I hope it's clear what my Problem is. I'm working now about 12 Days but didn't found out how it works.

Thank you!

King Regards

korunos
  • 768
  • 3
  • 11
  • 31
  • I would suggest you make a utility class and post all your logic of writing and retrieving data from xml there. You can then use this utility class in activities that you need – Raghunandan Jul 24 '15 at 08:26

1 Answers1

1

Use startactivityforresult() and @override onactivityresult for the first Activity to save and restore position line in XML file. For instance, read this topic: https://stackoverflow.com/a/10407371/1979882

Community
  • 1
  • 1
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
  • It sounds like a good solution!! Can you show me how to write the text or image given by the SingleTaskAktivity to the TaskListAktivity in the same position? I hope it's clear what i mean. – korunos Jul 24 '15 at 08:30
  • Thank you until yet so much!! Do you know how i can use at last the position? – korunos Jul 24 '15 at 08:44
  • I do not understand which last position do you mean? – Vyacheslav Jul 24 '15 at 16:43