I'm trying to do a written report on some code and I found one on youtube. However I don't understand what is going on exactly. I understand that it get's the ID of a certain object which then opens in a new Java class but if someone could breakdown what is happening it would be greatly appreciated.
private void setUpOnclickListener()
{
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l)
{
Supplier selectSupplier = (Supplier) (listView.getItemAtPosition(position));
Intent showDetail = new Intent(getApplicationContext(), DetailActivity.class);
showDetail.putExtra("id",selectSupplier.getId());
startActivity(showDetail);
}
});
}
CodePudding user response:
at first read some doc, what IS an Activity
, then read how to start new one, and why Intent
is needed for this
in short: this Intent
is carrying information what dev want to start/open (will start new "window" - DetailActivity
) and what will be passed to this component (some id)
CodePudding user response:
The code gets the supplier that is clicked on in the listview in order to gain their supplier id. That ID is then given to the DetailActivity page using an intent, whereby it will be used to display the details that relate to the specific supplier. On the DetailActivity page, the intent and its extra information, namely the supplier id, will be retrieved, and then can be used to display the details for the specific supplier that was clicked on on the previous page.