滚动的TextView里面AlertDialog [Android版] [英] Scrollable Textview inside AlertDialog [Android]

查看:646
本文介绍了滚动的TextView里面AlertDialog [Android版]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个Alertdialog内滚动的TextView。这是我对我的alertDialog内膨胀滚动视图XML。我不断收到此错误IllegalStateException异常:指定的小孩已经有一个家长,你必须首先对孩子的父母打电话removeView()。

难道有什么不对我的布局?由于我只使用了一次布局

 <?XML版本=1.0编码=UTF-8&GT?;<滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT><的LinearLayout
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=垂直>    <的TextView
        机器人:ID =@ + ID / invalid_recipients
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginLeft =16dip
        机器人:layout_marginRight =16dip
        机器人:layout_marginTop =4dip
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>
< / LinearLayout中>< /滚动型>

编辑:我膨胀的对话框,并在onPostExecute方法中的AsyncTask访问的TextView。这里是该方法的第一个位

  @覆盖
        保护无效onPostExecute(虚空V){
            如果(!invalidRecipientEmails.isEmpty()){
                AlertDialog.Builder certBuilder =新AlertDialog.Builder(
                        MessageCompose.this);
                最后查看recipientsLayout = getLayoutInflater()膨胀(R.layout.message_recipient_scrollview,NULL);
                最终的TextView recipientsTextView =(TextView中)recipientsLayout.findViewById(R.id.invalid_recipients);
                recipientsTextView.setText(invalidRecipientsString);
                certBuilder.setView(recipientsTextView);
                //设置alertdialog属性休息
            }
         }


解决方案

使用XML没有问题。
显示你的java code在您尝试使用。

更新:您必须设置

  certBuilder.setView(recipientsLayout);

而不是

  certBuilder.setView(recipientsTextView);

I want to have a scrollable textview inside an Alertdialog. This is my xml for the scrollview which I inflate inside the alertDialog. I keep getting this error "IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first."

Could it be that there is something wrong with my layout? Because I'm only using the layout once.

<?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>

EDIT: I am inflating the dialog and accessing the textview in an AsyncTask in the onPostExecute method. Here is the first bit of that method.

        @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
            }
         }

解决方案

With xml no problem. Show your java code where you try use.

UPDATE: you must set

certBuilder.setView(recipientsLayout); 

instead of

certBuilder.setView(recipientsTextView);

这篇关于滚动的TextView里面AlertDialog [Android版]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆