Created
September 22, 2015 08:55
-
-
Save vaibhav-jani/512ca43f5bc78d3eac2e to your computer and use it in GitHub Desktop.
Custom Dialog
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
| import android.app.Dialog; | |
| import android.os.Bundle; | |
| import android.text.TextUtils; | |
| import android.view.View; | |
| import android.view.Window; | |
| import android.widget.Button; | |
| import android.widget.EditText; | |
| import com.routerunner.R; | |
| import com.routerunner.activity.BaseActivity; | |
| /** | |
| * Created by vaibhav.jani on 09-Jul-15. | |
| */ | |
| public class CustomDialog extends Dialog implements android.view.View.OnClickListener { | |
| public BaseActivity activity; | |
| public Dialog dialog; | |
| public Button btnCancel; | |
| public Button btnAdd; | |
| public EditText etName; | |
| private OnTextCompletionListener onCompletionListener; | |
| public CustomDialog(BaseActivity a, OnTextCompletionListener onCompletionListener) { | |
| super(a); | |
| this.activity = a; | |
| this.onCompletionListener = onCompletionListener; | |
| } | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| setContentView(R.layout.dialog_product_search); | |
| btnCancel = (Button) findViewById(R.id.btnCancel); | |
| btnAdd = (Button) findViewById(R.id.btnAdd); | |
| etName = (EditText) findViewById(R.id.etName); | |
| btnCancel.setOnClickListener(this); | |
| btnAdd.setOnClickListener(this); | |
| } | |
| @Override | |
| public void onClick(View v) { | |
| switch (v.getId()) { | |
| case R.id.btnCancel: | |
| dismiss(); | |
| break; | |
| case R.id.btnAdd: | |
| add(); | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| private void add() { | |
| String name = etName.getText().toString(); | |
| if(!TextUtils.isEmpty(name)) { | |
| if(onCompletionListener != null) { | |
| onCompletionListener.onCompletion(name); | |
| } | |
| dismiss(); | |
| } | |
| } | |
| public void setOnCompletionListener(OnTextCompletionListener onCompletionListener) { | |
| this.onCompletionListener = onCompletionListener; | |
| } | |
| public static interface OnTextCompletionListener { | |
| void onCompletion(String name); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment