android – Open new screen with user's options clicked

Question:

I have a listView and in it I put all the users in the database, I use an adapterView to get the position and the id, but I don't know how I will open a new screen for the advanced options for each user.

follow the code

protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
      .permitAll().build();
    StrictMode.setThreadPolicy(policy);
      setContentView(R.layout.list);
      listView = (ListView) findViewById(R.id.listView1);
      accessWebService();

      listView.setOnItemClickListener(new OnItemClickListener() {
             public void onItemClick(AdapterView<?> parent, View view,
                 int position, long id) {
               // When clicked, show a toast with the TextView text
               Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                   Toast.LENGTH_SHORT).show();
             }
           });

     }

Would I have to bind some identifier attribute on the item to get it, or can I do it all with Json?

Answer:

listDebitosPendentes.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                  Intent intent = new Intent(getApplicationContext(), DetalhesDebitosActivity.class);

                  //Passa para a activity o id no banco de dados
                  intent.putExtra("ID", id);

                  startActivity(intent);
        }

    });

In the other activity you get it as follows.

 Long idSelected = getIntent().getLongExtra("ID", 0);

In my case I do a query getting this ID.

int id = Integer.valueOf(idSelected.toString());

debitosPendentes = debitoPendentesDao.queryForId(id);
Scroll to Top