Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. How to retrieve data in sqlite with intent

How to retrieve data in sqlite with intent

Scheduled Pinned Locked Moved Android
databasesqlitehelptutorial
9 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Muhammad H Alhasanat
    wrote on last edited by
    #1

    Dears I want to send data form one activity to another activity i use intent to send data when i use on item click listener this this my code for first activity

    Quote:

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {

                Intent i = new Intent(getApplicationContext(),Details.class);
                i.putExtra("id",position);
    
                startActivity(i);
    
            }
        });
    

    know the second activity to get intnet is

    ublic class Details extends AppCompatActivity {
    DBAdapter myDbHelper = new DBAdapter(this);

    SQLiteDatabase database;
    
    int item;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity\_details);
        TextView t1=(TextView)findViewById(R.id.t1);
        ImageButton im=(ImageButton)findViewById(R.id.im);
        Intent data=getIntent();
        int des=data.getIntExtra("id", 1);
        //String s= String.valueOf(des);
        //
        // Cursor sq= myDbHelper.myDataBase.rawQuery("select \* from sweet where description = '"+des+"')",null);
        try {
            //SELECT description  FROM sweet  where id =2
            //String query = "SELECT \* FROM sweet WHERE " + des + " = name";
             String query = "SELECT description FROM sweet WHERE id = " + des + "";
                   database=myDbHelper.openDataBase();
                  database = myDbHelper.getReadableDatabase();
           //Cursor sq = myDbHelper.myDataBase.rawQuery("select \* from sweet", null);
               Cursor cursor = database.rawQuery(query, null);
            cursor.getCount();
            cursor.moveToFirst();
               String description= cursor.getColumnName(2);
                t1.setText(description);
        }
    

    know i want to use intent to use it in sql statment to search in my table and get the details in the column description and put the text of details in text view can any one help me

    L D 2 Replies Last reply
    0
    • M Muhammad H Alhasanat

      Dears I want to send data form one activity to another activity i use intent to send data when i use on item click listener this this my code for first activity

      Quote:

      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView parent, View view, int position, long id) {

                  Intent i = new Intent(getApplicationContext(),Details.class);
                  i.putExtra("id",position);
      
                  startActivity(i);
      
              }
          });
      

      know the second activity to get intnet is

      ublic class Details extends AppCompatActivity {
      DBAdapter myDbHelper = new DBAdapter(this);

      SQLiteDatabase database;
      
      int item;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity\_details);
          TextView t1=(TextView)findViewById(R.id.t1);
          ImageButton im=(ImageButton)findViewById(R.id.im);
          Intent data=getIntent();
          int des=data.getIntExtra("id", 1);
          //String s= String.valueOf(des);
          //
          // Cursor sq= myDbHelper.myDataBase.rawQuery("select \* from sweet where description = '"+des+"')",null);
          try {
              //SELECT description  FROM sweet  where id =2
              //String query = "SELECT \* FROM sweet WHERE " + des + " = name";
               String query = "SELECT description FROM sweet WHERE id = " + des + "";
                     database=myDbHelper.openDataBase();
                    database = myDbHelper.getReadableDatabase();
             //Cursor sq = myDbHelper.myDataBase.rawQuery("select \* from sweet", null);
                 Cursor cursor = database.rawQuery(query, null);
              cursor.getCount();
              cursor.moveToFirst();
                 String description= cursor.getColumnName(2);
                  t1.setText(description);
          }
      

      know i want to use intent to use it in sql statment to search in my table and get the details in the column description and put the text of details in text view can any one help me

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Take a look at Handling Input and Storage on Android[^].

      M 1 Reply Last reply
      0
      • L Lost User

        Take a look at Handling Input and Storage on Android[^].

        M Offline
        M Offline
        Muhammad H Alhasanat
        wrote on last edited by
        #3

        ok

        1 Reply Last reply
        0
        • M Muhammad H Alhasanat

          Dears I want to send data form one activity to another activity i use intent to send data when i use on item click listener this this my code for first activity

          Quote:

          lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView parent, View view, int position, long id) {

                      Intent i = new Intent(getApplicationContext(),Details.class);
                      i.putExtra("id",position);
          
                      startActivity(i);
          
                  }
              });
          

          know the second activity to get intnet is

          ublic class Details extends AppCompatActivity {
          DBAdapter myDbHelper = new DBAdapter(this);

          SQLiteDatabase database;
          
          int item;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity\_details);
              TextView t1=(TextView)findViewById(R.id.t1);
              ImageButton im=(ImageButton)findViewById(R.id.im);
              Intent data=getIntent();
              int des=data.getIntExtra("id", 1);
              //String s= String.valueOf(des);
              //
              // Cursor sq= myDbHelper.myDataBase.rawQuery("select \* from sweet where description = '"+des+"')",null);
              try {
                  //SELECT description  FROM sweet  where id =2
                  //String query = "SELECT \* FROM sweet WHERE " + des + " = name";
                   String query = "SELECT description FROM sweet WHERE id = " + des + "";
                         database=myDbHelper.openDataBase();
                        database = myDbHelper.getReadableDatabase();
                 //Cursor sq = myDbHelper.myDataBase.rawQuery("select \* from sweet", null);
                     Cursor cursor = database.rawQuery(query, null);
                  cursor.getCount();
                  cursor.moveToFirst();
                     String description= cursor.getColumnName(2);
                      t1.setText(description);
              }
          

          know i want to use intent to use it in sql statment to search in my table and get the details in the column description and put the text of details in text view can any one help me

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          What is the value of query? So what EXACTLY is the problem?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          M 2 Replies Last reply
          0
          • D David Crow

            What is the value of query? So what EXACTLY is the problem?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            M Offline
            M Offline
            Muhammad H Alhasanat
            wrote on last edited by
            #5

            who to use the get intent to use the position of item to serche in database

            D 1 Reply Last reply
            0
            • M Muhammad H Alhasanat

              who to use the get intent to use the position of item to serche in database

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Muhammad H Alhasanat wrote:

              who...

              You want to know WHO can use it? That seems an odd question. Anyway, have you stepped through the code line by line using the debugger to see what is going on? What is the value of des? Of query?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              • D David Crow

                What is the value of query? So what EXACTLY is the problem?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                M Offline
                M Offline
                Muhammad H Alhasanat
                wrote on last edited by
                #7

                the value is get intent form first activity

                D L 2 Replies Last reply
                0
                • M Muhammad H Alhasanat

                  the value is get intent form first activity

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  So the value of query is "get intent form first activity"? Well no wonder your code does not work; That is not a valid SELECT statement! :rolleyes:

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  1 Reply Last reply
                  0
                  • M Muhammad H Alhasanat

                    the value is get intent form first activity

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    It is quite a simple matter to display the full text of your query to see exactly what values it contains.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups