Last active
July 31, 2018 16:04
-
-
Save MamdouhAlShamy/41bf0223a9cdc4b391fbe2dc18dc52b6 to your computer and use it in GitHub Desktop.
onClickListner RecyclerViewAdapter Callback machnism
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeatherActivity extends AppCompatActivity implements WeatherAdapter.onDayClickListener { | |
@Override | |
public void dayClicked(List dayWeather) { | |
Intent intent = new Intent(this, WeatherDetailsActivity.class); | |
startActivity(intent); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeatherAdapter extends RecyclerView.Adapter<WeatherAdapter.ViewHolder>{ | |
.... | |
interface onDayClickListener{ | |
void dayClicked(List dayWeather); | |
} | |
private onDayClickListener mCallback; | |
public WeatherAdapter(java.util.List<List> weatherDataList, Context context){ | |
... | |
mCallback = (onDayClickListener) context; | |
} | |
@Override | |
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) { | |
// Binding Code | |
holder.mView.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
mCallback.dayClicked(weatherDataList.get(position)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment