Pick time and notify user

Asked

Viewed 84 times

2

I created this code in Android Studio to inform the hours of the buses here in my city but I wanted the app to inform what the next bus the person could get as soon as she accessed the list view and I have no idea how to do it.

Follow the code of the list view:

public class Roncoroni extends AppCompatActivity {

    private ArrayList<TemOnibusTeste> adicionarOnibus() {

        ArrayList<TemOnibusTeste> onibusTestes = new ArrayList<TemOnibusTeste>();
        TemOnibusTeste e = new TemOnibusTeste("Segunda a sexta", "");
        onibusTestes.add(e);

        e = new TemOnibusTeste("Bairro          Centro", "");
        onibusTestes.add(e);

        e = new TemOnibusTeste("05:50             N/A*", "");
        onibusTestes.add(e);

        e = new TemOnibusTeste("N/A* = Não fica parado no Centro. Chega e sai.", "");
        onibusTestes.add(e);

        return onibusTestes;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.petroita_roncoroni);

        ListView lista = (ListView) findViewById(R.id.ListViewId);
        ArrayAdapter adapter = new TemOnibusAdapter(this, adicionarOnibus());
        lista.setAdapter(adapter);

    }
}

It would be more or less like this:

Não como grid view mas como list view

This is a print of my app:

inserir a descrição da imagem aqui

Temonibusteste class:

public class TemOnibusTeste {

    private String nome;
    private String via;

    public TemOnibusTeste(String nome, String via) {
        this.nome = nome;
        this.via = via;

    }

    public TemOnibusTeste(String s) {
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getVia() {
        return via;
    }

    public void setVia(String via) {
        this.via = via;

    }
}
  • Also include the class TemOnibusTeste, so that we know what is being saved for each bus

  • I updated the post Isac. I hope you can help me.

  • But if your bus class doesn’t have any date and time information it has no way of knowing if you are starting or not

  • So I’m in doubt! I don’t even know where to start!

  • Well the first steps would even include the date and time information within each bus. You can do it using the format Date for example. Then you would have to change the Adapter properly to display this information, as well as to insert it when creating bus. Then to know if there are any to leave you will have to consult the information of the buses, what would be more appropriate if it had stored somewhere, whether in Sqlite or firebase, otherwise it would not be able to persist the same between the various activities

  • Even wanting to do everything in memory as in the question would have to go through the various buses with a loop and calculate the current date distance to each of the ones on the list and save only those that are less than X minutes away. As you can see, there’s still a long way to go!

  • Our Isac! Thank you very much! I will try to do as you say!

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.