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

  • SEARCH
  • Home
  • 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 7308709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:35:43+00:00 2026-05-28T23:35:43+00:00

I’ve one listView with multiple choice and checkbox. I get the values from listview

  • 0

I’ve one listView with multiple choice and checkbox.
I get the values from listview executing a query in sqlite3.
When i click a button, I need to insert the selected items in another table but i don’t know how can i do it.
Before doing insert i’m trying to know if it works showing one console log (Log.v). in this code there is not insert statement.
Any suggestions? Thanks in advance and sorry about my english,

Alex.

I paste the code:

public class productos extends Activity  {
    SQLiteDatabase db;
Spinner prodSpinner;
ArrayAdapter<String> prodAdapter; 

Spinner catSpinner;
ArrayAdapter<String> catAdapter;
Cursor catCursor;

Cursor prodCursor;
String Value2;
String valor2;
SparseBooleanArray sp;   

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.productos);

    Bundle extras = getIntent().getExtras();
    //final String Value = extras.getSerializable("Lista").toString();
    //final String Value2 = extras.getSerializable("Super").toString();
    Button CatText2 = (Button) findViewById(R.id.textCategoria);
    CatText2.setOnClickListener(new OnClickListener() {

    public void onClick(View arg0) {
        Log.v("valor4:", "AAAAA");
        recCatSpinner();
        } 
  });
    Button btSelecciona = (Button) findViewById(R.id.btSelecciona);
    btSelecciona.setOnClickListener(new OnClickListener() {
    public void onClick (View arg0) {
         Toast.makeText(getBaseContext(),"AAAA",Toast.LENGTH_SHORT).show();
    }
    });  

    Button btComanda = (Button) findViewById(R.id.btComanda);
    btComanda.setOnClickListener(new OnClickListener() {
    public void onClick (View arg0) {
        EscriuComanda();
    }

    private void EscriuComanda() {
            final ListView prodSpinner = (ListView) findViewById(R.id.spProductes);
            int count = 0;
            //
            sp = new SparseBooleanArray();
            //SparseBooleanArray sp=prodSpinner.getCheckedItemPositions();
            sp.clear();
            sp = prodSpinner.getCheckedItemPositions();
             for(int i = 0; i < sp.size(); i++)
             {
                        if ( sp.valueAt(i)==true)
                        {
                            Log.v("400", "SI: " + valor2); 
                        }
                else
                {
                     Log.v("500", "No: " + valor2);
                }
             }
        }   
    });  
//Toast.makeText(getBaseContext(),Value2,Toast.LENGTH_SHORT).show();
    recCatSpinner();            
}
public class UsuariosSQLiteHelper extends SQLiteOpenHelper {
    public UsuariosSQLiteHelper(Context contexto, String nombre,
                               CursorFactory factory, int version) {
        super(contexto, nombre, factory, version);
    }
    public void onCreate(SQLiteDatabase db) {
        Log.v("OnClickV", "1");
     }
    public void onUpgrade(SQLiteDatabase db, int versionAnterior, int versionNueva) {

        Log.v("OnClickV", "1");
     }
    }
public Cursor recuperaCategoria()
    {
final UsuariosSQLiteHelper usdbh =new UsuariosSQLiteHelper(this, "DBLlistaCompra", null, 1);
final SQLiteDatabase db = usdbh.getWritableDatabase();
String tableName = "Categorias";
String[] columns = {"_id","Nombre"};


 return db.query(tableName, columns, null, null, null, null, null);
    }

public Cursor recuperaProductos()
{
    final UsuariosSQLiteHelper usdbh =new UsuariosSQLiteHelper(this, "DBLlistaCompra", null, 1);
    final SQLiteDatabase db = usdbh.getWritableDatabase();
    String tableName = "ArtSuperV";
    String[] columns = {"_id","NombreA"};
    String where = "NombreC='" + valor2 + "'";

    return db.query(tableName, columns, where, null, null, null, null);
}
public void recCatSpinner() {
        final ListView prodSpinner = (ListView) findViewById(R.id.spProductes);

        catCursor = recuperaCategoria();
        catCursor.moveToPosition(1);
        catAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);  //.simple_list_item_multiple_choice);// .simple_spinner_item); 
        catAdapter.setDropDownViewResource (android.R.layout.simple_list_item_multiple_choice); //.simple_spinner_dropdown_item);
        prodSpinner.setAdapter(catAdapter);
        if (catCursor.moveToFirst()) { 
          do { 
             catAdapter.add(catCursor.getString(1)); 
         } 
          while (catCursor.moveToNext()); 
          if (db != null) { 
          Toast.makeText(getBaseContext(),catCursor.getString(1),Toast.LENGTH_SHORT).show();
          db.close(); 
          } 
        } 
        startManagingCursor(catCursor);
        catCursor.close();
        prodSpinner.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent,
                View view2, int pos, long id) {
                valor2 = parent.getItemAtPosition(pos).toString();
                Toast.makeText(getBaseContext(),valor2,Toast.LENGTH_SHORT).show();
                Log.v("valor2:", valor2);
                recProdSpinner(); 
                }
        });
}
        public void recProdSpinner() {
            final ListView prodSpinner = (ListView) findViewById(R.id.spProductes);

            prodCursor = recuperaProductos();
            prodCursor.moveToPosition(1);
            prodAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice);  //.simple_list_item_multiple_choice);// .simple_spinner_item); 
            prodSpinner.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
            prodAdapter.setDropDownViewResource (android.R.layout.simple_list_item_multiple_choice); //.simple_spinner_dropdown_item);
            prodSpinner.setAdapter(prodAdapter);
            if (prodCursor.moveToFirst()) { 
              do { 
                 prodAdapter.add(prodCursor.getString(1));
                 } 
              while (prodCursor.moveToNext()); 
              if (db != null) { 
              Toast.makeText(getBaseContext(),prodCursor.getString(1),Toast.LENGTH_SHORT).show();
              db.close(); 
              } 
            } 
            startManagingCursor(prodCursor);
            prodCursor.close();
            prodSpinner.setOnItemClickListener(
            new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent,
                    View view2, int pos, long id) {
                    valor2 = parent.getItemAtPosition(pos).toString();
                    Toast.makeText(getBaseContext(),valor2,Toast.LENGTH_SHORT).show();
                    Log.v("valor2:", valor2);

                }
            });

        }

}

  • 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-05-28T23:35:43+00:00Added an answer on May 28, 2026 at 11:35 pm

    Cant figure out some of the code flow due to language issue.
    But scheme should be:
    1. Set the adapters for both the lists (even if the lists are empty on launch, set the adapter with the empty but initialised array lists and make the array list as the global variables of the class so that they can be accessed from anywhere in the activity.)
    2. Now select the items from the list1 and get their index in the first list.
    3. Add those items in the second array list.
    4. Call the “notifyDataSetChanged()” for the adapter of the second list view.

    Link to know about proper use of “notifyDataSetChanged()” are
    notifyDataSetChanged example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.