How to retrieve data in sqlite with intent
-
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
-
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
-
Take a look at Handling Input and Storage on Android[^].
ok
-
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
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
-
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
who to use the get intent to use the position of item to serche in database
-
who to use the get intent to use the position of item to serche in database
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
? Ofquery
?"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
-
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
the value is get intent form first activity
-
the value is get intent form first activity
So the value of
query
is "get intent form first activity"? Well no wonder your code does not work; That is not a validSELECT
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
-
the value is get intent form first activity