0

我使用片段,当我单击编辑文本时,会显示带有特殊键盘的布局(许多按钮可单击),但我找不到检测按钮单击的正确方法

这是 onCreateView 代码:

        public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
    {
        View view = inflater.inflate(R.layout.fragment_rsslist_overview,container, false);
                try {
                    setKeys();

                } catch (Exception e) {
                    Log.w(getClass().getName(), e.toString());
                }
        //

        return view;
    }

这是 setKeys 代码:(我在 mBSpace 按钮上尝试了很多东西)

        public void setKeys() {
        mWindowWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth(); // getting
        // window
        // height
        // getting ids from xml files
        mB[0] = (Button) getActivity().findViewById(R.id.xA);
        mB[1] = (Button) getActivity().findViewById(R.id.xB);
        mB[2] = (Button) getActivity().findViewById(R.id.xC);
        mB[3] = (Button) getActivity().findViewById(R.id.xD);
        mB[4] = (Button) getActivity().findViewById(R.id.xE);
        mB[5] = (Button) getActivity().findViewById(R.id.xF);
        mB[6] = (Button) getActivity().findViewById(R.id.xG);
        mB[7] = (Button) getActivity().findViewById(R.id.xH);
        mB[8] = (Button) getActivity().findViewById(R.id.xI);
        mB[9] = (Button) getActivity().findViewById(R.id.xJ);
        mB[10] = (Button) getActivity().findViewById(R.id.xK);
        mB[11] = (Button) getActivity().findViewById(R.id.xL);
        mB[12] = (Button) getActivity().findViewById(R.id.xM);
        mB[13] = (Button) getActivity().findViewById(R.id.xN);
        mB[14] = (Button) getActivity().findViewById(R.id.xO);
        mB[15] = (Button) getActivity().findViewById(R.id.xP);
        mB[16] = (Button) getActivity().findViewById(R.id.xQ);
        mB[17] = (Button) getActivity().findViewById(R.id.xR);
        mB[18] = (Button) getActivity().findViewById(R.id.xS);
        mB[19] = (Button) getActivity().findViewById(R.id.xT);
        mB[20] = (Button) getActivity().findViewById(R.id.xU);
        mB[21] = (Button) getActivity().findViewById(R.id.xV);
        mB[22] = (Button) getActivity().findViewById(R.id.xW);
        mB[23] = (Button) getActivity().findViewById(R.id.xX);
        mB[24] = (Button) getActivity().findViewById(R.id.xY);
        mB[25] = (Button) getActivity().findViewById(R.id.xZ);
        mB[26] = (Button) getActivity().findViewById(R.id.xS1);
        mB[27] = (Button) getActivity().findViewById(R.id.xS2);
        mB[28] = (Button) getActivity().findViewById(R.id.xS3);
        mB[29] = (Button) getActivity().findViewById(R.id.xS4);
        mB[30] = (Button) getActivity().findViewById(R.id.xS5);
        mB[31] = (Button) getActivity().findViewById(R.id.xS6);
        mBSpace = (Button) getActivity().findViewById(R.id.xSpace);
        mBdone = (Button) getActivity().findViewById(R.id.xDone);
        mBChange = (Button) getActivity().findViewById(R.id.xChange);
        mBack = (Button) getActivity().findViewById(R.id.xBack);
        mNum = (Button) getActivity().findViewById(R.id.xNum);
//      for (int i = 0; i < mB.length; i++)
        mBSpace.setOnClickListener( this);
/*      
        mBSpace.setOnClickListener( new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    edittext_onClick(v );
                }
              });
*/          
/*          
            mB[i].setOnClickListener( this);
        mBSpace.setOnClickListener( this);
        mBdone.setOnClickListener( this);
        mBack.setOnClickListener( this);
        mBChange.setOnClickListener( this);
        mNum.setOnClickListener( this);
//      mNum.setOnClickListener( this);
*/      


    }

有人知道他正确的语法对此做了什么吗?我尝试将 setkey() 调用为:

    public void onActivityCreated (Bundle savedInstanceState){
    setKeys();
    super.onActivityCreated(savedInstanceState);
}

我没有错误,但也没有点击检测......提前谢谢......

4

2 回答 2

1

您是否在 EditText 的 xml 元素中尝试过 android:clickable="true" ?

于 2013-02-20T10:02:32.697 回答
0

确保特殊键盘布局是当前 contentView 的一部分。如果不是,并且您将其膨胀到当前视图中,那么当您获取对按钮的引用时,您应该使用

buttonA = inflatedLayout.findViewById(R.id.button);

还要创建一个通用的 onClickListener 并将所有按钮绑定到它

OnClickListener buttonClickListener = new OnClickListener() {

      @Override
            public void onClick(View v) {

                edititext.setText(v.getTag().toString()); 
                // or whatever logic you are using

            }

}
于 2013-02-20T10:15:01.400 回答