如何打开搜索片段的“自定义”对话框,然后从该片段中获取值以在edittext中进行设置? Android Studio

时间:2019-07-11 17:16:08

标签: android-studio android-fragments android-dialogfragment customdialog googleplacesautocomplete

我想从应该在对话框中的位置自动完成片段中获取价值,并希望在“编辑”文本中设置搜索到的位置。

public class MainActivity extends FragmentActivity
{
final Context context = this;

private EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    editText = (EditText) findViewById(R.id.editText);


    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openDialog();
        }
    });

}

public void openDialog()
{


    LayoutInflater li = LayoutInflater.from(context);
    View promptsView = li.inflate(R.layout.activity_get_value, null);

    android.app.AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

    alertDialogBuilder.setView(promptsView);
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();

    }
}

0 个答案:

没有答案