我在Android上部署了我的应用程序。
我在我的主Activity按钮中放了一个,当你点击时,你必须显示一个对话框,我在2 EditText上写文字并按下OK按钮。
我的问题是......如何在主Activity的事件中获取EditText的值?
onDialogPositiveClick(...)
onDialogNegativeClick(...)
这是我的对话 DialogAlex.java
的课程public class DialogAlex extends DialogFragment {
public interface NoticeDialogListener {
public void onDialogPositiveClick(DialogFragment dialog,int id);
public void onDialogNegativeClick(DialogFragment dialog,int id);
}
NoticeDialogListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (NoticeDialogListener) activity;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement NoticeDialogListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_signin, null)) //This layout contains only two EditText, ET1 and ET2.
.setPositiveButton("adicionar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.onDialogPositiveClick(DialogAlex.this,id);
}
})
.setNegativeButton("cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.onDialogNegativeClick(DialogAlex.this, id);
}
});
return builder.create();
}
}
这是我的活动主页。
...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
if (id == R.id.telefono)
{
showNoticeDialog(); //call dialog
return true;
}
return super.onOptionsItemSelected(item);
}
public void showNoticeDialog() {
DialogFragment dialog = new DialogAlex();
dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
}
@Override
public void onDialogPositiveClick(DialogFragment dialog,int id) {
//**************HOW obtaining values EditText?*****************************
Toast.makeText(this,"hola", Toast.LENGTH_LONG).show();
}
@Override
public void onDialogNegativeClick(DialogFragment dialog,int id) {
}
...
问候
答案 0 :(得分:1)
您可以将其添加到界面的方法中。 E.g。
public interface NoticeDialogListener {
public void onDialogPositiveClick(DialogFragment dialog, String value, int id);
public void onDialogNegativeClick(DialogFragment dialog,int id);
}
然后
onCreateDialog
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.dialog_signin, null);
builder.setView(view) .setPositiveButton("adicionar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
EditText edittext = (EditText) view.findViewById(R.id.editText)
mListener.onDialogPositiveClick(DialogAlex.this, edittext.getText().toString(), id);
}
})
答案 1 :(得分:1)
你真的很接近,你必须通过你的听众传递这些价值。
将您的界面更改为:
public interface NoticeDialogListener {
public void onDialogPositiveClick(String input1, String input2);
public void onDialogNegativeClick();
}
然后更改onCreateDialog
以利用此功能:
final View view = inflater.inflate(R.layout.dialog_signin, null);
builder.setView(view) //This layout contains only two EditText, ET1 and ET2.
.setPositiveButton("adicionar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
EditText et1 = (EditText) view.findViewById(R.id.et1);
EditText et2 = (EditText) view.findViewById(R.id.et2);
String input1 = et1.getText().toString();
String input2 = et2.getText().toString();
mListener.onDialogPositiveClick(input1, input2);
}
})
.setNegativeButton("cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.onDialogNegativeClick();
}
});
return builder.create();
然后您的界面实现变为:
@Override
public void onDialogPositiveClick(String input1, String input2) {
Toast.makeText(this,"hola " + input1 + " " + input2, Toast.LENGTH_LONG).show();
}
答案 2 :(得分:0)
试试这段代码。
#!/bin/bash
#
# Make one PDF per page using PDF toolkit.
# Convert this PDF to SVG using inkscape
#
inputPdf=$1
pageCnt=$(pdftk $inputPdf dump_data | grep NumberOfPages | cut -d " " -f 2)
for i in $(seq 1 $pageCnt); do
echo "converting page $i..."
pdftk ${inputPdf} cat $i output ${inputPdf%%.*}_${i}.pdf
inkscape --without-gui "--file=${inputPdf%%.*}_${i}.pdf" "--export-plain-svg=${inputPdf%%.*}_${i}.svg"
done