我是android的新手所以我不知道编码这就是为什么我的代码看起来非常混乱抱歉 题: 当我点击问题按钮时没有任何反应,所以我的问题是我必须这样做,当我点击问题按钮时,一个对话框必须显示不同的消息,与我之前的对话框是alertuserabouterror(),我不想要再次创建另一个AlertUserAboutError.java类
先谢谢
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();
}}}
答案 0 :(得分:0)
使用与默认警报对话框相比易于使用的自定义AlertDialogBox或创建另一个AlertDialogBOx