Android 从其他类访问布局文本视图(无类)

Android 从其他类访问布局文本视图(无类),android,class,android-layout,android-alertdialog,android-custom-view,Android,Class,Android Layout,Android Alertdialog,Android Custom View,我有一个带有文本视图的自定义对话框布局,但它没有类。在OnOptions ItemSelected中的主要活动中,我有一个“关于”(在工具栏中),它显示了一个带有该自定义布局的对话框。我想访问并设置该文本视图以显示版本名。我该怎么做?以下操作不起作用: 主要活动: public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_setti

我有一个带有文本视图的自定义对话框布局,但它没有类。在OnOptions ItemSelected中的主要活动中,我有一个“关于”(在工具栏中),它显示了一个带有该自定义布局的对话框。我想访问并设置该文本视图以显示版本名。我该怎么做?以下操作不起作用: 主要活动:

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        Intent i = new Intent(this,Settings.class);
        startActivity(i);
    } else if (id == R.id.action_about){
        **TextView tvvn = (TextView)findViewById(R.id.tvvn);
        tvvn.setText(BuildConfig.VERSION_NAME);**

        AlertDialog dialog = new AlertDialog.Builder(this)
                .setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))
                .create();
        dialog.show();
    }
这样做:

            View v = getLayoutInflater().inflate(R.layout.custom_dialog, null);
            TextView tvvn = (TextView)v.findViewById(R.id.tvvn);
            tvvn.setText(BuildConfig.VERSION_NAME);
            AlertDialog dialog = new AlertDialog.Builder(this)
                .setView(v)
                .create();
            dialog.show();

布局设计可能有问题。尝试用xml对文本进行编码,看看是否正确appearing@mubeen我硬编码,它工作了。问题在于上面代码中的启动部分。自定义对话框布局是一个带有两个文本视图的简单布局。