Transfer data from one activity to another

Kamikaze Stifler

I would like to transfer the value of a spinner component in the first activity to an sqlite query in the second activity. going the value throught a Spinner.

First Activity - Filtro_Activity

package br.exemplosqlite;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class Filtro_Activity extends Activity implements      AdapterView.OnItemSelectedListener {

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

    //referencia a Spinner
    //Spinner coligada;

    //final TextView nome = (TextView)findViewById(R.id.txvNome);
    //final TextView sobrenome = (TextView)findViewById(R.id.txvSobrenome);
    //final Spinner pday = (Spinner)findViewById(R.id.spinner);
    final Spinner spcoligada = (Spinner)findViewById(R.id.coligada);
    final Spinner spfilial = (Spinner)findViewById(R.id.filial);
    final Spinner splestoque = (Spinner)findViewById(R.id.lestoque);
    final Spinner spgprodutos = (Spinner)findViewById(R.id.gprodutos);
    final Spinner spsubprodutos = (Spinner)findViewById(R.id.subproduto);
    final Spinner spclprodutos = (Spinner)findViewById(R.id.clprodutos);



    //spinner = (Spinner)findViewById(R.id.spinner);

    ArrayAdapter adaptercoligada=ArrayAdapter.createFromResource(this, R.array.coligada, android.R.layout.simple_spinner_item);
    spcoligada.setAdapter(adaptercoligada);

    ArrayAdapter adapterfilial=ArrayAdapter.createFromResource(this, R.array.filial, android.R.layout.simple_spinner_item);
    spfilial.setAdapter(adapterfilial);

    ArrayAdapter adapterlestoque=ArrayAdapter.createFromResource(this, R.array.lestoque, android.R.layout.simple_spinner_item);
    splestoque.setAdapter(adapterlestoque);

    ArrayAdapter adaptergprodutos=ArrayAdapter.createFromResource(this, R.array.gprodutos, android.R.layout.simple_spinner_item);
    spgprodutos.setAdapter(adaptergprodutos);

    ArrayAdapter adaptersubprodutos=ArrayAdapter.createFromResource(this, R.array.subproduto, android.R.layout.simple_spinner_item);
    spsubprodutos.setAdapter(adaptersubprodutos);

    ArrayAdapter adapterclprodutos=ArrayAdapter.createFromResource(this, R.array.clprodutos, android.R.layout.simple_spinner_item);
    spclprodutos.setAdapter(adapterclprodutos);

    Button ok = (Button)findViewById(R.id.btnok);


    ok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //chamada para a nova Activity
            Intent intent = new Intent(Filtro_Activity.this, ListUsersActivity1.class);
            intent.putExtra("coligada", spcoligada.getSelectedItem().toString());
            intent.putExtra("filial", spfilial.getSelectedItem().toString());
            intent.putExtra("lestoque", splestoque.getSelectedItem().toString());
            intent.putExtra("gprodutos", spgprodutos.getSelectedItem().toString());
            intent.putExtra("subprodutos", spsubprodutos.getSelectedItem().toString());
            intent.putExtra("clprodutos", spclprodutos.getSelectedItem().toString());

            //intent.putExtra("nomePessoa", nome.getText().toString());
            //intent.putExtra("sobrenomePessoa", sobrenome.getText().toString());
            //intent.putExtra("day", pday.getSelectedItem().toString());

            startActivity(intent);
        }
    });
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

}

And the other activity is :

package br.exemplosqlite;

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

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class BD extends Activity {





private SQLiteDatabase bd;

public BD(Context context) {
    BDCore auxBd = new BDCore(context);
    bd = auxBd.getWritableDatabase();
}



public List<Produtos> buscar2() {

    List<Produtos> list = new ArrayList<Produtos>();
    String[] colunas = new String[]{"_id","item", "coligada","filial"};
    //String whereclausula = "coligada = 'issue'";

    Cursor cursor = bd.rawQuery("select * from produtos2 ", null);
    //Cursor cursor = bd.query("produtos", colunas,null, null, null, null,null);
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        do {

            Produtos p = new Produtos();
            p.setId(cursor.getLong(0));
            p.setItem(cursor.getString(1));
            p.setColigada(cursor.getString(2));
            p.setFilial(cursor.getString(3));
            list.add(p);

        } while (cursor.moveToNext());
    }

    return (list);
 }

As you can see, the second activity has a db.query which I would like to modify with the spinner values from the first activity. Is this possible and what would be the best way to go about it?

Vishal Thakkar

just on your BD Class you have to get Value from intent which You pass from first Activity like this

And Main thing is that you pass value in intent to other Activity Not BD so you cant get it in that Activity

replace This line in fitro_activity

Intent intent=new Intent(this,BD.class);intent.putExtra("coligada","Your Spinner selected Value");startActivity(intent);

In your BD Class On Create write this

Intent i = getIntent(); String spn1 = i.getString("coligada");

whatever Value you set in putextra of fitroActivity with key of "coligada" you get it in sp1 string.you can check it using print on Toast or Log

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to transfer data from one activity to another in android

From Dev

How to transfer data from one activity to another and set it to the textview?

From Dev

Transfer Socket from one Activity to another

From Dev

want to transfer the image from one activity to another

From Dev

Can we share or transfer data from one Activity to another Activity using SharedPreference?

From Dev

how to transfer more then one string from one activity to another in android

From Dev

Transfer data from one table to another on insert

From Dev

Transfer data from one database to another with Datamapper

From Dev

Transfer a string from list view on one activity to another in android

From Dev

Parceling objects in android to transfer from one activity to another

From Dev

How to transfer a Uri image from one activity to another?

From Dev

Sending data from one activity to another startactivityforresult

From Dev

Passing data from one activity to another and then printing

From Dev

Notifying data change from one activity to another

From Dev

Sending data from one activity to another startactivityforresult

From Dev

How to parse data from one activity to another

From Dev

How to transfer a data from fragment which is started another fragment to an activity

From Dev

How to pass the data from listview of one activity and pass it to another activity?

From Dev

Number of ways to pass data from one activity to another activity

From Dev

getting error when passing data from one activity to another activity

From Dev

Python script to transfer data from one MySQL server to another one

From Dev

Transfer data from one database to another database with different schema

From Dev

How to transfer data from one table to another 2 tables

From Dev

Transfer data from one table to another in sql server

From Dev

How transfer data from one app to another app in android

From Dev

How to transfer data from one table of a database to a table in another database

From Dev

Transfer specific data from one whole worksheet to another

From Dev

PostgreSQL copy/transfer data from one database to another

From Dev

Data transfer from one pc to another using pulse coded modulation

Related Related

  1. 1

    How to transfer data from one activity to another in android

  2. 2

    How to transfer data from one activity to another and set it to the textview?

  3. 3

    Transfer Socket from one Activity to another

  4. 4

    want to transfer the image from one activity to another

  5. 5

    Can we share or transfer data from one Activity to another Activity using SharedPreference?

  6. 6

    how to transfer more then one string from one activity to another in android

  7. 7

    Transfer data from one table to another on insert

  8. 8

    Transfer data from one database to another with Datamapper

  9. 9

    Transfer a string from list view on one activity to another in android

  10. 10

    Parceling objects in android to transfer from one activity to another

  11. 11

    How to transfer a Uri image from one activity to another?

  12. 12

    Sending data from one activity to another startactivityforresult

  13. 13

    Passing data from one activity to another and then printing

  14. 14

    Notifying data change from one activity to another

  15. 15

    Sending data from one activity to another startactivityforresult

  16. 16

    How to parse data from one activity to another

  17. 17

    How to transfer a data from fragment which is started another fragment to an activity

  18. 18

    How to pass the data from listview of one activity and pass it to another activity?

  19. 19

    Number of ways to pass data from one activity to another activity

  20. 20

    getting error when passing data from one activity to another activity

  21. 21

    Python script to transfer data from one MySQL server to another one

  22. 22

    Transfer data from one database to another database with different schema

  23. 23

    How to transfer data from one table to another 2 tables

  24. 24

    Transfer data from one table to another in sql server

  25. 25

    How transfer data from one app to another app in android

  26. 26

    How to transfer data from one table of a database to a table in another database

  27. 27

    Transfer specific data from one whole worksheet to another

  28. 28

    PostgreSQL copy/transfer data from one database to another

  29. 29

    Data transfer from one pc to another using pulse coded modulation

HotTag

Archive