I am new in android so i dont know correctly to code thats why my code looking very messy sorry for that Question: When i click on issue button nothing happens so my question is to what i have to do so that when i click on issue button a dialog box have to appear with different message as compared to my previous dialog which is alertuserabouterror() and i dont want to create another AlertUserAboutError.java class again
Thanks in advancce
MainActivity.this
public class MainActivity extends AppCompatActivity {
private Button issueButton;
private Button reissueButton;
private Button returnButton;
private EditText mEditText;
public AlertDialogFragment malert;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
issueButton = (Button) findViewById(R.id.issueid);
reissueButton = (Button) findViewById(R.id.reissueid);
returnButton = (Button) findViewById(R.id.returnid);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
issueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialogFragment.thads();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
alertuserAboutError();
return true;
}
if (id == R.id.action_about) {
Intent intent = new Intent(this, About.class);
startActivity(intent);
}
return true;
}
public void alertuserAboutError() {
final AlertDialogFragment dialog = new AlertDialogFragment();
dialog.show(getFragmentManager(), "Dialog");
}}
AlertDialogFragment.java
public class AlertDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
private EditText editQuantity;
private EditText editQuantity2;
private TextView text;
Database data;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
editQuantity = new EditText(getActivity());
editQuantity.setInputType(InputType.TYPE_CLASS_TEXT);
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.app_name)
.setMessage("Please Enter TIME")
.setPositiveButton("OK", this)
.setNegativeButton("CANCEL", null)
.setView(editQuantity)
.create();
}
@Override
public void onClick(DialogInterface dialog, int position) {
String date=editQuantity.getText().toString();
try{ editQuantity.setText(" ");
int newdate=Integer.parseInt(date);
if(newdate>0) {
data.putreturn(newdate);
Toast.makeText( getActivity(), "Date Updated", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
else{
Toast.makeText(getActivity(),"Please enter a valid number ", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}
catch (Exception e){
Toast.makeText( getActivity() ,"Date Updated", Toast.LENGTH_SHORT).show();
}
}
public static class thads extends AlertDialogFragment{
private EditText editQuantity2;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
editQuantity2 = new EditText(getActivity());
editQuantity2.setInputType(InputType.TYPE_CLASS_TEXT);
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.app_name)
.setMessage("Please Enter TIME")
.setPositiveButton("OK", this)
.setNegativeButton("CANCEL", null)
.setView(editQuantity2)
.create();
}}}