Break lines in a list coming from the bank

0

I have this Dao that does a Search to the Database Sql Server

    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 upon receiving the data, it comes in the list in sequence and does not break the line. How to do this line break?

    
asked by anonymous 28.02.2018 / 15:54

2 answers

0

You are returning the join of the array and not the concatenation of the items in the recebeNome variable which should be used to receive your error messages as well. Follow the changed method.

public String nomeTabela() {

        String nomeData = "";
        String nomeAlarme = "";
        String nomeRecebe = "";
        ConexaoDao conexao = new ConexaoDao();
        ObjetoConexao objConexao = new ObjetoConexao();
        objConexao.db_connect_string = "********";
        objConexao.db_name = "Celular";
        objConexao.db_userid = "****";
        objConexao.db_password = "******";
        Connection conn = conexao.dbConnect(objConexao);

        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);

        while (rs.next()) {
            nomeData = rs.getString("E3TimeStamp");
            nomeAlarme = rs.getString("Message");

            nomeRecebe += (nomeData + " " + nomeAlarme + '\n');               

        }
    } catch (SQLException e) {
        nomeRecebe = e.getMessage();
    }

    return nomeRecebe;
}

}

    
28.02.2018 / 18:11
0

look where the error was.

   ArrayAdapter<String> arrayAdapter = new  ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,Teste);

Here it is like this

ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, Test);

obeyed

    
28.02.2018 / 19:26