Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to retrieve only one row from local sqlite database in edit text.And there should be button on click event of that button it should show second row and so on.On showing row it should also delete that row from local sqlite database so that it won`t be repeated .

Here is my Database Helper Class
Java
public class DataBaseHelper extends SQLiteOpenHelper { 
public static final String db_name = "sms.db"; 
public static final int version = 2; 
Context context; 
public DataBaseHelper(Context context) { 
super(context, db_name, null, version); 
this.context = context; 
} 
@Override 
public void onCreate(SQLiteDatabase db) { 
// TODO Auto-generated method stub 
db.execSQL("create table datatable(number VARCHAR(10),message VARCHAR(25))"); 
Toast.makeText(context, "Database Created", Toast.LENGTH_LONG).show(); 
} 
@Override 
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
// TODO Auto-generated method stub 
if (oldVersion >= newVersion) 
return; 
if (oldVersion == 1) { 
Log.d("New Version", "Datas can be upgraded"); 
} 
Log.d("Sample Data", "onUpgrade : " + newVersion); 
} 
} 


Here is my mainactivity class

Java
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
String tablename = "datatable"; 
String numb=""; 
String mess = ""; 

IF = new IntentFilter(); 
IF.addAction("SMS_RECEIVED_ACTION"); 
SQLiteDatabase db = null; 
DataBaseHelper dd = new DataBaseHelper(getBaseContext()); 
dd.getWritableDatabase(); 
db= openOrCreateDatabase("sms.db", SQLiteDatabase.CREATE_IF_NECESSARY, null); 
Cursor cc = db.rawQuery("SELECT * FROM datatable", null); 
//cc.moveToFirst(); 
if(cc.getCount()>=1) { 
cc.moveToFirst(); 

try { 
for(int i=0;i < cc.getCount();i++){ 
String number = cc.getString(0); 
String message = cc.getString(1); 
numb += number; 
mess += message; 
DisplayText(numb,mess); 
count ++; 
} 
count ++; 
cc.moveToNext(); 
}catch (Exception e) { 
// TODO: handle exception 
}cc.close(); 
} 
} 
private void DisplayText(final String numb, final String mess) { 
// TODO Auto-generated method stub 

final EditText et3 = (EditText) findViewById(R.id.editText3); 
final EditText et4 = (EditText) findViewById(R.id.editText4); 
Button bt1 = (Button) findViewById(R.id.button1); 
bt1.setOnClickListener(new OnClickListener() { 

@Override 
public void onClick(View v) { 
// TODO Auto-generated method stub 

et3.setText(numb); 
et4.setText(mess); 

} 
}); 

} 


Now forget about deleting but right now after this program i am getting one row displayed 3 times i.e there are 3 rows so it displayed 1 row three times.I want one row to be displayed 1 time and on button click i want another row and so on.
Posted
Comments
ZurdoDev 3-Oct-13 7:40am    
So, just select 1 row at a time instead of all of them or implement paging.
Member 10312798 3-Oct-13 8:12am    
But i want to display one row then on button click it should display another row.
ZurdoDev 3-Oct-13 8:14am    
That's what paging is. Or, in the button click get the next row.
Member 10312798 3-Oct-13 8:16am    
But i want that row data in edit text And then i wll call webservice and send that data...

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