我想在 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
}
}