Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8253721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:58:16+00:00 2026-06-08T00:58:16+00:00

This Question has been modified to show working code. When they click an item

  • 0

This Question has been modified to show working code.

When they click an item such as Steak, I want that item to be placed into another list. If they then select Potatoes, that too should be added to this new list such that at the end I would have a list that shows all the items the user selected. Here is what I have so far.

LunchListMenu.java

package com.mycompany.lunch;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class LunchListMenu extends Activity {  

    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maincoarse);
        final ListView lv=(ListView)findViewById(R.id.listView1);              
        ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(this, R.array.lunch_menu,android.R.layout.simple_list_item_1);
        lv.setAdapter(adapter);
        final ArrayList<String> myNewList = new ArrayList<String>();
        lv.setOnItemClickListener(new OnItemClickListener() {



            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {  
                String item=lv.getItemAtPosition(arg2).toString();
                String itemordered;
                itemordered = item + " added to list";
                Toast.makeText(getApplicationContext(), itemordered, Toast.LENGTH_SHORT).show();
                myNewList.add(item);                
            }
        });

                // List View Button
                Button btnLunchList = (Button) findViewById(R.id.lrList);
                btnLunchList.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {                       
                        setContentView(R.layout.selecteditems);
                        ListView selecteditems = (ListView) findViewById(android.R.id.list);
                        ArrayAdapter<String> newadapter = new ArrayAdapter<String>(LunchListMenu.this, android.R.layout.simple_list_item_1, myNewList);              
                        selecteditems.setAdapter(newadapter);
                    }
                });
    }
                    public void shareMyList(View v){
                        // Share Selected Items Button
                        Button btnShareItems = (Button) findViewById(R.id.shareMyList);
                        btnShareItems.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                // TODO Auto-generated method stub

                                Intent share = new Intent(Intent.ACTION_SEND);
                                share.setType("text/plain");
                                share.putExtra(Intent.EXTRA_TEXT, "I'm being sent!!");
                                startActivity(Intent.createChooser(share, "Share Text"));
                            }


                        });
                    }
}

I also created a New Layout called selecteditems.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:background="@drawable/main_background" 
  android:paddingLeft="10.0dip" 
  android:paddingTop="0.0dip" 
  android:paddingRight="10.0dip" 
  android:paddingBottom="10.0dip" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="100.0dip"
            android:background="@drawable/title" />

        <LinearLayout 
            android:orientation="horizontal" 
            android:background="@drawable/head" 
            android:layout_width="fill_parent" 
            android:layout_height="10.0dip" />    

          <ListView 
              android:id="@android:id/list"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textSize="25dip"
              android:textStyle="bold"
              android:padding="10dip"
              android:textColor="#ffffff"/>

</LinearLayout>

It now adds the Item to the new selecteditems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:58:17+00:00Added an answer on June 8, 2026 at 12:58 am

    Just create an arrayList and put your items into it, then find your “other list” and feed that list with this arrayList.

     ArrayList<String> myNewList = new ArrayList<String>();
    

    on your ItemClick:

     myNewList.add(item);
    

    and then whenever you want to set your list:

    ListView newList = (ListView) findViewById(R.id.your_new_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, myNewList, android.R.layout.simple_list_item_1);
    newList.setAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SEE EDIT UPDATES BELOW. Original question has been modified! I have a working window
I realize that this question has been asked before - but none of the
I'm sorry for this as there has been lots instances of such question, but
This question has been asked before but i still don't understand it fully so
This question has been bugging me for a long time now but essentially I'm
This question has been asked in a C++ context but I'm curious about Java.
This question has been puzzling me for a long time now. I come from
This question has been asked in various forms in a number of different forums,
This question has been bugging me for some time. I always picture launching my
This question has been asked before but the answers aren't always clear or are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.