0
I have this Dao that does a search to the Sql Server Database
public String nomeTabela() {
String nomeData = "";
String nomeAlarme = "";
String nomeRecebe = "";
ConexaoDao conexao = new ConexaoDao();
ObjetoConexao objConexao = new ObjetoConexao();
objConexao.db_connect_string = "******.****.**:****";
objConexao.db_name = "********";
objConexao.db_userid = "****";
objConexao.db_password = "*******";
Connection conn = conexao.dbConnect(objConexao);
ArrayList list = null;
if (conn == null) {
nomeRecebe = "Não foi possivel se conectar ao banco de dados";
} else if (conn != null) try {
Statement statement = conn.createStatement();
String queryString = "select TOP 100 Area,E3TimeStamp,Message from Alarmescelular Where AREA = ' Elevatória R7' order By E3TimeStamp DESC ";
ResultSet rs;
rs = statement.executeQuery(queryString);
list = new ArrayList();
while (rs.next()) {
nomeData = rs.getString("E3TimeStamp");
nomeAlarme = rs.getString("Message");
nomeRecebe = (nomeData + " " + nomeAlarme + "\n");
list.add(nomeRecebe);
}
} catch (SQLException e) {
nomeRecebe = e.getMessage();
}
return String.valueOf(list);
}
}
and I have an activit that receives the data
public class Act_Historico_Alarme extends AppCompatActivity implements View.OnClickListener {
private Spinner Estacoes;
private Button btnFechar;
private Button btnPesquisar;
String ESTACAO1 = "BIBLIOTECA UFV";
String ESTACAORECEBIDA;
Dao_Historico_Alarme DHA;
String FalhaCon = "Não foi possivel se conectar ao banco de dados";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_historico_alarme);
Estacoes = (Spinner) findViewById(R.id.Spn_Estacoes);
btnFechar = (Button) findViewById(R.id.btnFechar);
btnFechar.setOnClickListener(this);
btnPesquisar = (Button) findViewById(R.id.btnPesquisar);
btnPesquisar.setOnClickListener(this);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.Sistema_Mobile, android.R.layout.simple_spinner_item);
Estacoes.setAdapter(adapter);
final AdapterView.OnItemSelectedListener escolha = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = Estacoes.getSelectedItem().toString();
ESTACAORECEBIDA = item;
Toast.makeText(getApplicationContext(),ESTACAORECEBIDA, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
Estacoes.setOnItemSelectedListener(escolha);
}
private ArrayList<String> preencherDados() {
String nomeRecebeAL1;
DHA = new Dao_Historico_Alarme();
nomeRecebeAL1 = DHA.nomeTabela();
ArrayList<String> dados = new ArrayList<String>();
dados.add(nomeRecebeAL1);
return dados;
}
public void onClick(View v) {
if (v.getId() == R.id.btnFechar) {
finish();
} else if (v.getId() == R.id.btnPesquisar) {
ListView Lista = (ListView) findViewById(R.id.List_Dados);
ArrayList<String> Teste = preencherDados();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Teste);
Lista.setAdapter(arrayAdapter);
}}}
But when receiving the data, it comes in the list in sequence and does not break the line. How to do this line break?
Tried a " r n" instead of just " n"? But from your print it looks like you’re writing an array and not a string with the breaks
– Leandro Angelo
I tried but it’s still the same
– Ronaldo Santos