DialogFrament没有认出我的行动

时间:2015-09-01 11:08:49

标签: android android-dialogfragment

我有一个dialogFragment,它的组件布局和一个管理其动作的类。一切都很好。我想在对话框中选择布局组件时返回一个值 - 我该怎么做?

该对话框由一组布局组成,这些布局附有一个动作侦听器。我不知道在哪里放这个 - 但是不能让对话框对任何按下布局做出反应。

我的xml

    <LinearLayout xmlns:android='http://schemas.android.com/apk/res/android'
        android:id='@+id/background'
        android:layout_width='fill_parent'
        android:layout_height='fill_parent'
        android:orientation='vertical'
        android:padding='10sp'
        android:background="@color/green"
        android:baselineAligned="false">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="50dp">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"
                android:id="@+id/linearLayout_colorR1C1"
                android:clickable="true"
                android:background="#548235">

            </LinearLayout>

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:id="@+id/linearLayout_colorR1C2"
                android:background="#f100b050">

            </LinearLayout>
   </LinearLayout>
</LinearLayout>

我的对话类

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;


public class dialog_colorpicker extends android.app.DialogFragment implements OnEditorActionListener {


    public interface EditNameDialogListener {
        void onFinishEditDialog(String inputText);
    }

    private LinearLayout ll1R1C;

    public dialog_colorpicker() {
        // Empty constructor required for DialogFragment
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_colorpicker, container);
        ll1R1C = (LinearLayout) view.findViewById(R.id.linearLayout_colorR1C1);
        getDialog().setTitle("Team Colors");

        return view;
    }

//WHERE DO I LISTEN FOR LAYOUTCLICK AND RETURN THAT VALUE

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

    if (EditorInfo.IME_ACTION_DONE == actionId) {
        // Return input text to activity
        EditNameDialogListener activity = (EditNameDialogListener) getActivity();

        //Do something here to 

        activity.onFinishEditDialog("#ff00ff");
        this.dismiss();
        return true;
    }
    return false;
}

}

我的通话活动

    import android.support.v4.app.FragmentActivity;
    public class Game_AddFixtureTeams_Activity extends FragmentActivity implements EditNameDialogListener {
@Override
public void onCreate(Bundle savedInstanceState) {

    showEditDialog()
    }

    private void showEditDialog()
    {
        dialog_colorpicker editNameDialog = new dialog_colorpicker();
        editNameDialog.show(getFragmentManager(), "SOME_TAG");
    }

    @Override
    public void onFinishEditDialog(String inputText)
    {
        //do something after you get the value
        ll_primaryColor.setBackgroundColor(Color.parseColor(inputText));
    }
    }

1 个答案:

答案 0 :(得分:0)

知道了,我删除了onEditorAction并使用listenr更新了onCreate。完美。

LinearLayout myLinearLayout = (LinearLayout) cardView.findViewById(R.id.my_linear_layout);
myLinearLayout.removeAllViews();