Created
January 24, 2019 11:27
-
-
Save yudikarma/08a644f46d56d39b2a0fc2a8d62ab9c0 to your computer and use it in GitHub Desktop.
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
===========================in adapter ====================== | |
viewHolder.linecar.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
selected_position = i; | |
notifyDataSetChanged(); | |
Log.e("position",""+selected_position); | |
Intent intent = new Intent("custom-message"); | |
// intent.putExtra("quantity",Integer.parseInt(quantity.getText().toString())); | |
intent.putExtra("position",selected_position); | |
LocalBroadcastManager.getInstance(context).sendBroadcast(intent); | |
notifyDataSetChanged(); | |
} | |
}); | |
======================== THEN IN ACTIVITY OR FRAGMENT ============================== | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// Inflate the layout for this fragment | |
View rootView = inflater.inflate(R.layout.fragment_set_kind_timer,container,false); | |
recyclerView_kindtimer = rootView.findViewById(R.id.recycle_view_kind_timer); | |
prefManagerTimer = new PrefManagerTimer(getActivity()); | |
initRecycleView(); | |
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMessageReceiver, | |
new IntentFilter("custom-message")); | |
return rootView; | |
} | |
public BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// Get extra data included in the Intent | |
position = intent.getIntExtra("position",0); | |
} | |
}; | |
...thanks.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment