2013-10-25 6 views
0

toggleButton을 사용하면 코드를 누를 때 코드를 실행해야합니다. 그러나 그것은 전혀 작동하지 않습니다. 토글 버튼이 일반적으로하는 것처럼, 나는 그것을 누르고 그것을 바꿉니다. touchListener 코드를 전혀 호출하지 않습니다. 내 in_call_card.xml에서 나는이 :ontouchListener 코드가 실행되고 있지 않습니까?

<ToggleButton 
      android:id="@+id/PTT_button5" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent"    
      android:text="@string/ptt5" 
      android:layout_weight="50" 
      android:textOn="Push To Talk On" 
      android:textOff="Push To Talk Off" 
      android:background="@drawable/btn_lightblue_glossy" 
      android:textColor="@android:color/white" 
      android:textSize="15sp" 
      /> 

가에서 onCreate에 내가 in_card_main.xml에의 setContent 한 내가 in_call_card.xml의 버튼을 사용하여 레이아웃을 부풀려해야합니다. 여기에 내 코드이지만, 내가 버튼을 누르면입니다 때 실행되지 않습니다 :

LayoutInflater inflater = getLayoutInflater(); 
     View otherLayout = inflater.inflate(R.layout.in_call_card, null); 
     final ToggleButton toggle = (ToggleButton) otherLayout.findViewById(R.id.PTT_button5); 
     toggle.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       Toast.makeText(getApplicationContext(), "woot7", Toast.LENGTH_SHORT).show(); 
       //may need to change to loop and send all ids. 
       int callId = 0; 
       for (SipCallSession callInfo : callsInfo) { 
        callId = callInfo.getCallId(); 
        Log.e(TAG, ""+callInfo.getCallId()); 

       } 

       final int id= callId; 

        switch(event.getAction()) { 


        case MotionEvent.ACTION_DOWN: 
          toggle.setBackgroundResource(R.drawable.btn_blue_glossy); 
         toggle.setChecked(true); 
          OnDtmf(0, 17, 10); 
          OnDtmf(0, 16, 9); 
          OnDtmf(id, 17, 10); 
          OnDtmf(id, 16, 9); 
         break; 
        case MotionEvent.ACTION_UP: 
          //  Toast.makeText(getApplicationContext(), "woot", Toast.LENGTH_LONG).show(); 
         //release 
         toggle.setBackgroundResource(R.drawable.btn_lightblue_glossy); 
         toggle.setChecked(false); 
         OnDtmf(0, 18, 11); 
         OnDtmf(0, 18, 11); 
         OnDtmf(id, 18, 11);  
         OnDtmf(id, 18, 11);  
         break; 
        } 
        return false; 
      } 
     }); 

편집 :

in_call_main :

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    Copyright (C) 2010 Regis Montoya (aka r3gis - www.r3gis.fr) 

    This file is part of CSipSimple. 
    CSipSimple is free software: you can redistribute it and/or modify 
    it under the terms of the GNU General Public License as published by 
    the Free Software Foundation, either version 3 of the License, or 
    (at your option) any later version. 
    If you own a pjsip commercial license you can also redistribute it 
    and/or modify it under the terms of the GNU Lesser General Public License 
    as an android library. 

    CSipSimple is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    GNU General Public License for more details. 

    You should have received a copy of the GNU General Public License 
    along with CSipSimple. If not, see <http://www.gnu.org/licenses/>. 
--> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/mainFrame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ViewStub 
     android:id="@+id/dropZones" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout="@layout/in_call_drop_zones" /> 

    <LinearLayout 
     android:id="@+id/inCallContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="3" 
      android:orientation="horizontal" > 

      <!-- 
       Can we do better than using two linear layouts here? 
       The problem is that RelativeLayout doesn't allow to use weight and 
       plays bad with hidden childs and above/below only support one id 
      --> 
      <!-- Grid for active calls --> 

      <com.csipsimple.ui.incall.InCallInfoGrid 
       android:id="@+id/activeCallsGrid" 
       android:layout_width="0dip" 
       android:layout_height="match_parent" 
       android:layout_weight="2" 
       android:paddingBottom="4dip" 
       android:paddingTop="4dip" 
       tools:ignore="NestedWeights" /> 

      <!-- Grid for held calls --> 

      <com.csipsimple.ui.incall.InCallInfoGrid 
       android:id="@+id/heldCallsGrid" 
       android:layout_width="0dip" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@drawable/in_call_held_background" 
       android:padding="4dip" 
       android:visibility="gone" /> 
     </LinearLayout> 

     <!-- Answer slider/buttons --> 

     <com.csipsimple.ui.incall.locker.InCallAnswerControls 
      android:id="@+id/inCallAnswerControls" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="2" 
      android:visibility="gone" /> 

     <!-- Wraps split action bar manually managed --> 

     <com.csipsimple.ui.incall.InCallControls 
      android:id="@+id/inCallControls" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/incall_bottom_bar_bg" /> 
    </LinearLayout> 

    <com.csipsimple.ui.incall.locker.ScreenLocker 
     android:id="@+id/lockerOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#8000" 
     android:visibility="gone" > 

     <!-- 
     <TextView android:id="@+id/lockerIcon" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:gravity="center" android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" android:layout_marginBottom="70dip" 
      android:text="@string/touch_lock" android:textAppearance="?android:attr/textAppearanceLarge" 
      android:background="@drawable/dialpad_lock" /> 
     --> 
    </com.csipsimple.ui.incall.locker.ScreenLocker> 

     <!-- <ToggleButton 
      android:id="@+id/PTT_button3" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 

      android:text="@string/ptt3" 
      android:layout_weight="50" 
      android:textOn="Push To Talk On" 
      android:textOff="Push To Talk Off" 
      android:background="@drawable/btn_lightblue_glossy" 
      android:textColor="@android:color/white" 
      android:textSize="15sp" 
      /> --> 

</RelativeLayout> 

in_call_card :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/call_card_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF" 
    android:padding="2dip" 
    tools:ignore="Overdraw" > 

    <com.csipsimple.widgets.MaxScaleImageView 
     android:id="@+id/contact_photo" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/call_action_bar" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:contentDescription="@string/empty_description" 
     android:scaleType="centerCrop" 
     android:src="@drawable/ic_contact_picture_180_holo_light" /> 

    <RelativeLayout 
     android:id="@+id/contact_name_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#9e808080" 
     android:gravity="center_vertical" > 
    <!--  
      <EditText 
     android:id="@+id/editText1" 
     android:layout_width="150dp" 
     android:layout_height="wrap_content" 
     android:ems="10" > 



     <requestFocus /> 
     </EditText> 
     --> 

     <com.csipsimple.widgets.MarqueeTextView 
      android:id="@+id/contact_name_display_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:ellipsize="marquee" 
      android:marqueeRepeatLimit="marquee_forever" 
      android:padding="5dip" 
      android:singleLine="true" 
      android:textColor="@android:color/white" 
      android:textSize="25sp" /> 

     <com.csipsimple.widgets.MarqueeTextView 
      android:id="@+id/contact_name_sip_address" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/contact_name_display_name" 
      android:ellipsize="marquee" 
      android:marqueeRepeatLimit="marquee_forever" 
      android:padding="2dip" 
      android:singleLine="true" 
      android:textColor="@android:color/white" 
      android:textSize="15sp" /> 

     <Chronometer 
      android:id="@+id/elapsedTime" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:textSize="20sp" /> 


    </RelativeLayout> 

    <TextView 
     android:id="@+id/call_status_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/contact_name_bar" 
     android:layout_marginTop="1dip" 
     android:background="#c818617b" 
     android:gravity="center_vertical|right" 
     android:padding="3dip" 
     android:text="@string/call_state_calling" 
     android:textAllCaps="true" 
     android:textColor="@android:color/white" 
     android:textSize="15sp" /> 

    <RelativeLayout 
     android:id="@+id/call_secure_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/call_status_text" 
     android:layout_marginTop="1dip" 
     android:background="#c8d4aa00" > 


     <ImageView 
      android:id="@+id/call_secure_icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_margin="2dip" 
      android:contentDescription="@string/empty_description" 
      android:src="@drawable/stat_sys_vp_phone_call" /> 

     <TextView 
      android:id="@+id/call_secure_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_toRightOf="@+id/call_secure_icon" 
      android:padding="2dip" 
      android:textColor="@android:color/white" 
      android:textSize="15sp" /> 
    </RelativeLayout> 

    <FrameLayout 
     android:id="@+id/call_action_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/end_call_bar" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignWithParentIfMissing="true" 
     android:layout_marginTop="2dip" 
     android:background="#000000" /> 

    <LinearLayout 


     android:id="@+id/end_call_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="2dip" 
     android:background="@drawable/end_call_background" 
     android:orientation="horizontal" > 

     <!-- android:onClick="pushtotalk3" --> 
     <ToggleButton 
      android:id="@+id/PTT_button5" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 

      android:text="@string/ptt5" 
      android:layout_weight="50" 
      android:textOn="Push To Talk On" 
      android:textOff="Push To Talk Off" 
      android:background="@drawable/btn_lightblue_glossy" 
      android:textColor="@android:color/white" 
      android:textSize="15sp" 
      />  

     <ImageButton 
      android:id="@+id/endButton" 
      style="?attr/actionButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="50" 
      android:contentDescription="@string/done" 
      android:minHeight="64dip" 
      android:src="@drawable/ic_end_call" /> 


    </LinearLayout> 


</RelativeLayout> 
+0

청취자를 호출하지 않는다는 것을 어떻게 알 수 있습니까? – Simon

+0

Logcat? 앱 FC 또는 오류가 있습니까? 로그 또는 토스트가 기능에 도달했는지 확인하려고 했습니까? – Si8

+0

@Simon은 기록되지 않으며, 토스트 등은 없습니다. – Paul

답변

0

당신이 사용하는 경우 setContentView(int)findViewById(int) 액티비티는 y에 대한 XML을 부 풀리기 때문에 findViewById(int)을 사용해야합니다. 우.

화면에 표시되지 않는 버튼에 청취자를 넣으려는 순간 이 부풀려졌지만 활동이 보류되지 않은 것이 아닙니다.

이 솔루션 :

  • 당신에게 말할 사용 setContentView(R.layout.in_call_card) 당신이
  • 을 팽창 한 레이아웃을 표시하는 활동을 알려 만 findViewById(R.id.PTT_button5);를 사용하여 뷰를 검색 에 누락 종료 setContentView(otherLayout) 통화 추가 계층 구조에 ID 'R.id.PTT_button5'가있는보기를 검색하기 전에 'in_call_card'레이아웃을 표시하는 활동
+0

나를 혼란스럽게합니다. setContentView (otherLayout) 시도하고 단추가 표시되면 - 모양이 다르게 작동하지만 나머지 레이아웃은 모두 지금 중단됩니다. 버튼이 처음에 어떻게 표시 되었는가하는 것이 혼란 스럽습니다. 부풀려졌지만 아무 것도 붙이지 않았습니까? 나는이 버튼 하나를 추가하고 작동시키는 메인 레이아웃을 갖는 방법을 이해할 수 없다. 표시되고 작동하려면 두 XML 파일의 요소가 필요합니다. – Paul

+0

@Paul 레이아웃을 표시하지 않고 레이아웃을 확장 할 수 있습니다. 'setContentView (int)'를 사용하면 액티비티에 XML을 팽창시키고 표시하도록 지시한다. 그래서 당신이'myactivity.findViewById (int)'를 사용할 때 그것은 보유하고있는 팽창 된 뷰를 검색 할 것입니다. 그러나 XML 리소스를 직접 업로드 할 때 컨텐트 뷰로 설정하는 것을 잊어 버리면 ** 표시되지 않은 뷰를 사용하게됩니다 **. 이 경우에 당신이있는 것 같습니다. 그런 다음 2 가지 해결책 (예 : 내 대답)이 있습니다. – Flawyte

+0

내 편집 된 답변보기, 도움이되기를 바랍니다. – Flawyte

0

청취자가 아닙니다. 청취자는 ToggleButton 또는 다른 유형의보기와 함께 정상적으로 작동합니다. 마지막에 return false을 입력하면 onTouchListener이 호출되고 onClickListener (있는 경우)이 호출됩니다.

버튼을 눌렀을 때 아무것도 얻지 못하는 이유는 화면에 버튼이 없다는 것입니다.입니다. 당신은 당신의 코드에서 그것을 부 풀린다. 그러나 부모없이 나는 코드를 볼 수 없다. 실제로 어떤 레이아웃에 부풀려진 ToggleButton을 추가한다. 그래서, 당신이 누르는 화면에 무엇을 가지고 있든, 당신의 onTouchListener이 듣고있는 버튼이 아닙니다.

일부를 layout으로 만들거나 앱 디자인에 따라 LayoutActivity을 새로 만드는 것이 좋습니다.

EDIT 게시 된 레이아웃에 따르면.

제가 이해하는 것은 in_card_main.xmlin_call_card.xml의 두 가지 전체 레이아웃이 있지만 하나의 주소는 Activity입니다. 그게 맞습니까? 그렇다면 솔루션은 각 레이아웃에 대해 하나의 활동을 가지고 startActivity()으로 활동을 호출하는 것입니다.

+0

내가 그것을 부 풀리기 전에 내가 어떻게 버튼을 볼 수 있는지 정말 모르겠다. , 그리고 그것을 부 풀린 후에 그것은 붙어 있지 않습니다, 어떻게 내가 현재 화면에 추가 할 수 있습니다. 나는 그것이 심지어 인플레이션을 부르기 전에 그것이 화면에 나타나고 있다면, 분명히 뭔가 할 수있는 방법이 있어야한다는 것을 의미합니다. 나는 그것이 화면에있는 것처럼 보이는 레이아웃의 일부라고 생각했습니다. 나는 아무것도 팽창시켜야한다고 생각하지 않았다. 그러나 만일 내가하지 않으면 나는 널 포인터를 얻는다. – Paul

+0

화면에 표시되는 단추는 코드에서 부풀린 단추가 아닙니다.화면에있는 것은 레이아웃에 있어야합니다. 'in_card_main.xml'의 레이아웃을 게시 할 수 있습니까 (이미있는'in_call_card.xml'이 아닌)? 기본적으로 당신은 터치 리스너가 등록되어야하는 버튼이어야하는 메인 레이아웃의 버튼이 있다고 생각합니다. 그러나 먼저 주 레이아웃을 살펴 보도록하십시오. 아, 고마워. 고마워. 어디 보자 ... – jboi

+0

그래도 하나의 활동 예, 만약 내가 woulld 심지어 그것에 들어가서 다른 활동을했다? 저는 코드를 편집하고 있습니다.이 글을 쓰지 않았고, 따르지 않는 것은 레이아웃이 두 ​​개인 방법과 하나의 활동이지만 버튼은 모두 잘 작동하고 광산은 작동하지 않는다는 것입니다. 이러한 레이아웃의 화면에 버튼이 표시되면 실제로 작동하도록이 버튼을 연결하는 방법이 있습니다. 다른 활동을한다면, 내가 무엇을하고 있는지 확신 할 수 없습니다. onCreate에 리스너가 있습니까? – Paul

관련 문제