How to put array populated by other activity to arraylist


Last Updated:

  1. fighter123

    fighter123 New Member

    I am developing some application for android and i have problem.

    I push data with button click from another activity with intent to string of first activity, and i put from that string these data to listview by a adapter, and it is all ok, i mean i see on listview that data, but when i want to add new item in listview by click of button of second activity, i mean do again same thing, there is a problem: that data i push by a second button click replaces first button click data, and i want to add that data under first data in another listview row?

    here is code of activity where is a listview:

    package com.example.kupi;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    import android.R.array;
    import android.app.Activity;
    import android.app.ListActivity;
    import android.content.Intent;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.Toast;

    public class popis_kupaca extends Activity {
    public String ImeKupca;
    public String PrezimeKupca;
    public String OIBKupca;
    public String AdresaKupca;

    int i = 0;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.popis_kupaca);

    ListView listView1 = (ListView) findViewById(R.id.listViewpopiskupaca);
    listView1.setClickable(true);

    ImeKupca = " ";
    PrezimeKupca = " ";
    OIBKupca = " ";
    AdresaKupca = " ";

    Intent intent = getIntent();
    String[] values = intent.getStringArrayExtra("string-array");
    String[] items = {ImeKupca + " " + PrezimeKupca + " " + OIBKupca + " " + AdresaKupca };

    List<String> list = new ArrayList<String>();
    ArrayList<String> arrayList = new ArrayList<String>(list);

    if(values == null)
    {
    values = items;
    }
    else
    {
    ImeKupca = values[0];
    PrezimeKupca = values[1];
    OIBKupca = values[2];
    AdresaKupca = values[3];

    //items = new String[]{values[0] + " " + values[1] + " " + values[2] + " " + values[3] };
    //items = values[0] + " " + values[1] + " " + values[2] + " " + values[3];
    items = new String[]{values[0] + " " + values[1] + " " + values[2] + " " + values[3], "danas"};

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, items);
    listView1.setAdapter(adapter);
    }

    //Dodaj Botun
    Button pritisni4 = (Button) findViewById(R.id.dodaj1);
    pritisni4.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
    Intent myIntent = new Intent(view.getContext(), unos_kupca.class);
    startActivityForResult(myIntent, 0);
    i++;
    }
    });

    //Odustani Botun
    Button pritisni5 = (Button) findViewById(R.id.odustani1);
    pritisni5.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
    Intent myIntent = new Intent(view.getContext(), MainActivity.class);
    startActivityForResult(myIntent, 0);
    }
    });
    }
    }

    Advertisement
  2. RichSz

    RichSz Not Entitled VIP Member

    Moved to Application Development.

Share This Page