Click here to Skip to main content
15,883,127 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a large product list for a store. I want users to be able to click on items in the list so that it can be added into a smaller user list after it is clicked.

What I have tried:

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

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

import static;

* Created by keaberry on 3/8/2017.

public class CreateList2 extends AppCompatActivity implements
AdapterView.OnItemClickListener {
String[] items;
ArrayList<string> listItems;
ArrayAdapter<string> adapter;
ListView listView;
EditText editText;

protected void onCreate(Bundle savedInstanceState) {
editText.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int
count, int after) {


public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().equals("")){

public void afterTextChanged(Editable s) {



public void searchItem(String textToSearch){
for (String item:items){



public void initList(){
items=new String[]{"Bacon", "Milk","Cereal","Frozen Pizza","Sports Drinks","Cheese","Detergent","Chips","Pet Food"};
listItems=new ArrayList<>(Arrays.asList(items));
adapter=new ArrayAdapter<string>(this, R.layout.item_list,, listItems );


public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView temp=(TextView) view;
String Value = listView.getItemAtPosition(position).toString();
Toast.makeText(getApplicationContext(), Value, Toast.LENGTH_SHORT).show();
Updated 13-Apr-17 12:01pm
Richard Deeming 6-Apr-17 14:20pm    
You've told us what you want, and you've shown us the code you've written. But you haven't told us where you're stuck, or what the problem is with the code you've written.

1 solution

So far your code is only showing a Toast when the first list is clicked.

You also have only one list view apparently ( -> listView).

You need to add the second list view to the layout (R.layout.activity_create_list2), add another class variable for that list view and obtain that listView2 in your onCreate method.

Then in your existing onClick handler do the stuff to add to listView2. Given what you've already put together I think you should be able to work out how to do this yourself.

BTW Just to mention that your variable naming should really be following Google best practice, specifically non-static private class vars such as listView should be mListView. This clearly wouldn't make your app spring to life but makes it easier to share code with others (the "m" in mListView reads as "my listView").
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900