I Create a dialog in java and show it when a button was clicked, in this dialog I have a button , how can I set OnClickListener of this button? This code show my dialog:
ImageView iv = (ImageView) view.findViewById(R.id.ivTaskPlus); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Dialog d = new Dialog(getActivity()); d.getWindow().requestFeature(Window.FEATURE_NO_TITLE); d.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); d.setContentView(R.layout.task_new_layout); d.show(); } }); and in task_new_layout.xml i have this button:
<Button android:id="@+id/btnSaveTask" android:layout_marginTop="10sp" style="@style/btnSuccess" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/save_task" /> I create an onClickListener for this button but it wont work and has no error!!
final View taskView = inflater.inflate(R.layout.task_new_layout, container, false); Button btnSaveTask = (Button) taskView.findViewById(R.id.btnSaveTask); btnSaveTask.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.e("MGH","clicked"); } });