Prova un po....
codice:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ricerca);
Tbl_Data = (TableLayout)findViewById(R.id.Tbl_Data);
Fill_Table();
}
//***********************************************
private void Fill_Table() {
// cancelliamo eventuali righe precedenti
Tbl_Data.removeAllViews();
// variabili che mi servono tra poco
String id = "";
String voce_trovata = "";
// otteniamo tutte le ragioni sociali che soddisfano
// la ricerca
SqlStmt = " select distinct id, Ragione_Sociale ";
SqlStmt += " from dati_clienti ";
SqlStmt += " order by Ragione_Sociale ";
try {
Cursor cursor = crm_database.getWritableDatabase().rawQuery(SqlStmt, null);
while (cursor.moveToNext() ) {
id = cursor.getString(0).toString().trim();
voce_trovata = cursor.getString(1).toString().trim();
Fill_Table_Add_Row(id, voce_trovata);
}
}
catch(Exception ex) {
messaggio = ex.getMessage();
Txt_Message.setText(messaggio);
}
}
//***********************************************
private void Fill_Table_Add_Row(String id, String voce) {
// prepariamo il testo
TextView the_name = new TextView(this);
the_name.setText(voce);
the_name.setTextSize(18);
the_name.setTextColor(Color.DKGRAY);
the_name.setId( Integer.parseInt(id) );
// riga per contenere i componenti
TableRow riga = new TableRow(this);
riga.setBackgroundColor(Color.parseColor("#F0F0F0"));
riga.addView(the_name);
// aggiungiamo questa riga alla table
Tbl_Data.addView(riga);
}
... ovviamente il codice non è completo. Mancano il file delle risorse, l'accesso al database, etc.