0

我想在 Alertdialog 中有一个可滚动的文本视图。这是我在 alertDialog 中膨胀的滚动视图的 xml。我不断收到此错误“IllegalStateException:指定的孩子已经有父母。您必须先在孩子的父母上调用 removeView()。”

会不会是我的布局有问题?因为我只使用了一次布局。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/invalid_recipients"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dip"
        android:layout_marginRight="16dip"
        android:layout_marginTop="4dip"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

</ScrollView>

编辑:我正在膨胀对话框并在 onPostExecute 方法的 AsyncTask 中访问文本视图。这是该方法的第一部分。

        @Override
        protected void onPostExecute(Void v) {
            if (!invalidRecipientEmails.isEmpty()) {
                AlertDialog.Builder certBuilder = new AlertDialog.Builder(
                        MessageCompose.this);
                final View recipientsLayout = getLayoutInflater().inflate(R.layout.message_recipient_scrollview, null);
                final TextView recipientsTextView = (TextView) recipientsLayout.findViewById(R.id.invalid_recipients);
                recipientsTextView.setText(invalidRecipientsString);
                certBuilder.setView(recipientsTextView);
                // set rest of alertdialog attributes
            }
         }
4

2 回答 2

1

用xml没问题。在您尝试使用的地方显示您的 java 代码。

更新:你必须设置

certBuilder.setView(recipientsLayout); 

代替

certBuilder.setView(recipientsTextView);
于 2013-06-27T21:08:01.553 回答
0

从 ScrollView 参考:http: //developer.android.com/reference/android/widget/ScrollView.html

TextView 类也负责自己的滚动,因此不需要 ScrollView,但是将两者结合使用可以实现更大容器内的文本视图的效果。

于 2013-06-27T20:59:16.630 回答