How do I pass an item from a listview to another listview on android?

1

I have this list, which is where I want to pass the item through the popup menu

And the code is this:

public class route1 extends Activity {

ListView listaruta;
List<String> list = new ArrayList<String>();
ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ruta1);

    listaruta = (ListView) findViewById(R.id.listview_ruta1);
    list.add("Monitor");
    list.add("Keyboard");
    list.add("Mouse");
    list.add("Mother Board");
    list.add("Hard Disk");
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, list);
    listaruta.setAdapter(adapter);
    registerForContextMenu(listaruta);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId())
    {
        case R.id.delete_id:
            list.remove(info.position);
            adapter.notifyDataSetChanged();
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}

}

Now my question is: What should I put in case to achieve adding the desired item to the other listview?

Here is the pop menu and its code

Thank you.

    
asked by E7T14A 09.04.2017 в 22:52
source

1 answer

1

What you really want is to send a data from an Activity in a ListView to another Activity.

The sending of data between Activities is generally done by a Bundle in which values are added and that bundle is sent through a Intent to the Activity destination, get the value of the day to click on the element and add it to a bundle:

    Intent intent = new Intent(MainActivity.this, OtraActivity.class);
    intent.putExtra("diaListView", valorDia);
    startActivity(intent);      

When you upload the Activity destination via getExtras () , you'll receive the data in this way:

String valorDia = getIntent().getExtras().getString("diaListView");

or simply by:

String valorDia = getIntent().getStringExtra("diaListView");
    
answered by 12.04.2017 в 00:30