无法在TextInputLayout

时间:2018-07-07 12:25:47

标签: android android-edittext android-textinputlayout

我正在尝试为我的应用程序构建自定义AlertDialog,我希望能够以编程方式设置TextInputEditText。

我在this线程上阅读了我应该设置TextInputLayout提示的方法,我尝试了一下,但是它不起作用,没有错误,但是我仍然看到默认的提示消息,而不是我刚刚设置的消息。

public boolean onContextItemSelected(MenuItem item) {

        int position = -1;
        try {
            position = ((PurchaseAdapter) rvContacts.getAdapter()).getPosition();

        } catch (Exception e) {
            return super.onContextItemSelected(item);
        }
        if (item.getTitle() == "Show Dialog") {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            LayoutInflater inflater = this.getLayoutInflater();

            View content = inflater.inflate(R.layout.edit_purchase_details, null); //use this line to be able to use findviewbyId
            builder.setView(inflater.inflate(R.layout.edit_purchase_details, null));

            System.out.println("list_purchases.get(position).getName(): " + list_purchases.get(position).getName()); //not empty, returns a string "abcd"

            TextInputLayout etProd = content.findViewById(R.id.textInputLayoutProd);
            etProd.setHint(list_purchases.get(position).getName());

            builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {


                    }
                })
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // do nothing
                    }
                })
                .setIcon(android.R.drawable.ic_dialog_dialer)
                .show();
        }

0 个答案:

没有答案