0

I researched on the internet before asking the question and almost answer likely:

I believe this line is at fault:

View v = inflater.inflate(R.layout.weather_row, null, true);

You need instead:

View v = inflater.inflate(R.layout.weather_row, parent, false);

I did as instructed of answer but error:

UnsupportedOperationException: addView(View) is not supported in AdapterView at android.widget.AdapterView.addView

continues appear.

So, I post my code hope anyone can help me.

On event onActionItemsClicked when press to button Save Contact:

private InputPopupFrag mInputPopupFrag;
private FragmentManager mFragmentManager;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFragmentManager=getFragmentManager();
    mInputPopupFrag=new InputPopupFrag();
}

switch (item.getItemId()) {
     case R.id.saveContact:
             mFragmentManager.beginTransaction().replace(R.id.call_history_listview, mInputPopupFrag).commit();

This is class InputPopupFrag:

public class InputPopupFrag extends SimpleBaseFrag {
    @Override
    public BasePopupWindow getPopup() {
        return new InputPopup(mContext);
    }

    @Override
    public Button getButton() {
        return (Button) mFragment.findViewById(R.id.saveContact);
    }

    @Override
    public View getFragment() {
        return mInflater.inflate(R.layout.call_history_item,container,false);
    }
}

And InputPopup class:

public class InputPopup extends BasePopupWindow implements View.OnClickListener{
    private Button mCancelButton;
    private Button mCompeleteButton;
    private EditText mInputEdittext;

    public InputPopup(Activity context) {
        super(context);
        mCancelButton= (Button) mPopupView.findViewById(R.id.btn_cancel);
        mCompeleteButton= (Button) mPopupView.findViewById(R.id.btn_Compelete);
        mInputEdittext= (EditText) mPopupView.findViewById(R.id.ed_input);

        setAutoShowInputMethod(true);
        bindEvent();
    }

    @Override
    protected Animation getShowAnimation() {
        return null;
    }

    private void bindEvent() {
        mCancelButton.setOnClickListener(this);
        mCompeleteButton.setOnClickListener(this);
    }


    @Override
    public Animator getShowAnimator() {
        return getDefaultSlideFromBottomAnimationSet();
    }

    @Override
    public View getInputView() {
        return mInputEdittext;
    }

    @Override
    protected View getClickToDismissView() {
        return mPopupView;
    }

    @Override
    public View getPopupView() {
        return LayoutInflater.from(mContext).inflate(R.layout.popup_input,null);
    }

    @Override
    public View getAnimaView() {
        return mPopupView.findViewById(R.id.popup_anima);
    }

    @Override
    public Animator getExitAnimator() {
        AnimatorSet set = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            set = new AnimatorSet();
            if (getAnimaView() != null) {
                set.playTogether(
                        ObjectAnimator.ofFloat(getAnimaView(), "translationY", 0, 250).setDuration(400),
                        ObjectAnimator.ofFloat(getAnimaView(), "alpha", 1, 0.4f).setDuration(250 * 3 / 2));
            }
        }
        return set;
    }

    //=============================================================click event
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_Compelete:
                ToastUtils.ToastMessage(mContext,mInputEdittext.getText().toString());
                dismiss();
                break;
            default:
                break;
        }

    }
}

And layout contain id call_history_listview is ListView all item:

<?xml version="1.0" encoding="utf-8"?>
    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/call_history_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"/>

Finally is call_history_item is details of item in ListView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/row"
    android:layout_width="match_parent"
    android:layout_height="65.333dp"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="62dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="55sp"
                android:layout_height="match_parent"
                >

                <ImageView
                    android:id="@+id/caller_image"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/contact_image" />
            </LinearLayout>

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

                <TextView
                    android:id="@+id/caller_name_list"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="4dp"
                    android:text="Là là"
                    android:textSize="15sp" />

                <TextView
                    android:id="@+id/call_time_list"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="4dp"
                    android:text="Time"
                    android:textSize="14sp" />
            </LinearLayout>

            <TextView
                android:id="@+id/sending"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="7dp"
                android:layout_marginTop="4dp"
                android:textSize="14dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_marginRight="13dp"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/phone_number_list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="4dp"
                android:text="01012345678"
                android:textSize="14dp" />

            <TextView
                android:id="@+id/start_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:text="Date"
                android:textSize="14sp" />
        </LinearLayout>
    </FrameLayout>

    <RelativeLayout
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="2.333dp" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="bottom"
            android:background="@drawable/common_line_piece" />
    </RelativeLayout>

</RelativeLayout>
Lan Can
  • 15
  • 6
  • Can you show the code of BasePopupWindow and SimpleBaseFrag? Do you set the content view before you call replace(R.id.call_history_listview, mInputPopupFrag)? Because Android needs to know what to replace. If you wanna replace the whole content then Android provides the ID android.R.id.content – pczern Mar 22 '16 at 10:28
  • @speedDeveloper You can read more code at here: BasePopupWindow: http://pastebin.com/21UrspiQ and SimpleBaseFrag: http://pastebin.com/YQTPBVTp Thank you very much. – Lan Can Mar 22 '16 at 16:39
  • Do you set the content view before you call replace(R.id.call_history_listview, mInputPopupFrag)? Where's container or mInflater defined? @Override public View getFragment() { return mInflater.inflate(R.layout.call_history_item,container,false); } http://stackoverflow.com/questions/10253506/expandablelistview-unsupportedoperationexception-addviewview-layoutparams-i Somebody got a similar exception maybe something is false with the container variable. We need more information to find the problem. – pczern Mar 23 '16 at 19:01
  • Thanks @speedDeveloper. I changed new method to do this. – Lan Can Mar 24 '16 at 03:48

0 Answers0