2016-07-26 10 views
0

ここにコードです: これはほぼすべてのページに含まれており、このメニューでページをスローするようにナビゲートしたいですが、onClicksは、何も動作しません。ありがとうございました。含まれているレイアウトの画像ボタンは、アクションダウンのonclicklistenerを起動しません

public class BottomNavBar extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_bottom_nav_bar); 
    ImageButton schedule = (ImageButton) findViewById(R.id.btmSchedule); 
    ImageButton map = (ImageButton) findViewById(R.id.btmMap); 
    final ImageButton liveFeed = (ImageButton) findViewById(R.id.btmLivefeed); 
    ImageButton message = (ImageButton) findViewById(R.id.btmMessage); 
    ImageButton profile = (ImageButton) findViewById(R.id.btmProfile); 
    schedule.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View arg0, MotionEvent event) { 
      if (event.getAction() == MotionEvent.ACTION_DOWN) { 
       Intent intent = new Intent(getApplicationContext(), ScheduleActivity.class); 
       startActivity(intent); 
      } 

      if ((event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL)) { 

      } 
      return false; 
     } 
    }); 
    liveFeed.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Toast.makeText(BottomNavBar.this, "startedLiveFeed", Toast.LENGTH_SHORT).show(); 
      Intent intent = new Intent(getApplicationContext(),LiveFeedActivity.class); 
      startActivity(intent); 

     } 
    }); 
    profile.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(getApplicationContext(),UserProfile.class); 
      startActivity(intent); 

     } 
    }); 
    schedule.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(getApplicationContext(),ScheduleActivity.class); 
      startActivity(intent); 

     } 
    }); 
    message.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(getApplicationContext(),NewsActivity.class); 
      startActivity(intent); 

     } 
    }); 
    map.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(getApplicationContext(),VideosActivity.class); 
      startActivity(intent); 

     } 
    }); 
} 

のxml親

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:clickable="true" 
android:focusable="false"> 
<include layout="@layout/content_nav_bar" /> 

親コンテンツ

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:layout_weight="5" 
android:id="@+id/content_navbar" 
android:clickable="true" 
android:focusable="false"> 
<ImageButton 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:id="@+id/btmSchedule" 
    android:src="@drawable/schedule" 
    android:background="#F0F4F7" 
    android:layout_gravity="center|left" 
    android:scaleType="fitXY" 
    android:clickable="true" 
    android:contentDescription="@string/asd" /> 
<ImageButton 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/map" 
    android:id="@+id/btmMap" 
    android:background="#F0F4F7" 
    android:layout_gravity="center|left" 
    android:scaleType="fitXY" 
    android:clickable="true" 
    android:contentDescription="@string/asd" /> 
<ImageButton 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/livefeed" 
    android:id="@+id/btmLivefeed" 
    android:background="#F0F4F7" 
    android:layout_gravity="center|left" 
    android:scaleType="fitXY" 
    android:clickable="true" 
    android:contentDescription="@string/asd" 
    android:padding="5dp"/> 
<ImageButton 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/message" 
    android:id="@+id/btmMessage" 
    android:background="#F0F4F7" 
    android:layout_gravity="center|left" 
    android:scaleType="fitXY" 
    android:clickable="true" 
    android:contentDescription="@string/asd" /> 
<ImageButton 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:src="@drawable/profile" 
    android:id="@+id/btmProfile" 
    android:background="#F0F4F7" 
    android:layout_gravity="center|left" 
    android:scaleType="fitXY" 
    android:clickable="true" 
    android:contentDescription="@string/asd" /> 

+0

あなたはonClickListenerてみましたやった結果()?? –

+0

おそらく、android:focusable = "false" linearLayoutとclickable = trueの両方を削除しようとしました。 – Chol

+0

@Vivekはいいいえ運がよろしいですか?アドバイスありがとうございます。まだ動作しません。 –

答えて

1
public class FasTestFragment extends UtuBaseFragment implements 
     View.OnClickListener { 

    @Bind(R.id.btmSchedule) 
    ImageButton btmSchedule; 
    @Bind(R.id.btmMap) 
    ImageButton btmMap; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.test_include, container, false); 
     ButterKnife.bind(this, view); 
     return view; 
    } 

    @Override 
    public void onViewCreated(View view, Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 

     btmSchedule.setOnClickListener(this); 
     btmMap.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     int id = v.getId(); 
     if (id == R.id.btmSchedule) { 
      System.out.println("****Schedule clicked."); 
     }else if (id == R.id.btmMap) { 
      System.out.println("****map clicked."); 
     } 
    } 
} 

//test.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_weight="5" 
    android:id="@+id/content_navbar" 
    android:clickable="true" 
    android:focusable="false"> 
    <ImageButton 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:id="@+id/btmSchedule" 
     android:src="@drawable/fas_void" 
     android:background="#F0F4F7" 
     android:layout_gravity="center|left" 
     android:scaleType="fitXY" 
     android:clickable="true" 
     android:contentDescription="123" /> 
    <ImageButton 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/fas_user" 
     android:id="@+id/btmMap" 
     android:background="#F0F4F7" 
     android:layout_gravity="center|left" 
     android:scaleType="fitXY" 
     android:clickable="true" 
     android:contentDescription="123" /> 
    <ImageButton 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/fas_enquiry" 
     android:id="@+id/btmLivefeed" 
     android:background="#F0F4F7" 
     android:layout_gravity="center|left" 
     android:scaleType="fitXY" 
     android:clickable="true" 
     android:contentDescription="123" 
     android:padding="5dp"/> 
    <ImageButton 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/fas_payment" 
     android:id="@+id/btmMessage" 
     android:background="#F0F4F7" 
     android:layout_gravity="center|left" 
     android:scaleType="fitXY" 
     android:clickable="true" 
     android:contentDescription="123" /> 
    <ImageButton 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/fas_summary" 
     android:id="@+id/btmProfile" 
     android:background="#F0F4F7" 
     android:layout_gravity="center|left" 
     android:scaleType="fitXY" 
     android:clickable="true" 
     android:contentDescription="123" /> 

</LinearLayout> 

//test_include.xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:clickable="true" 
    android:focusable="false"> 
    <include layout="@layout/test" /> 

</LinearLayout> 

//

07-27 11:51:51.641 492-492/com.UTU I/System.out: ****Schedule clicked. 
07-27 11:51:51.761 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:51.831 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:51.831 492-492/com.UTU I/System.out: ****Schedule clicked. 
07-27 11:51:53.271 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:53.351 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:53.351 492-492/com.UTU I/System.out: ****map clicked. 
07-27 11:51:53.461 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:53.531 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:53.531 492-492/com.UTU I/System.out: ****map clicked. 
07-27 11:51:53.641 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:53.711 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:53.721 492-492/com.UTU I/System.out: ****map clicked. 
07-27 11:51:53.841 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:53.901 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:53.901 492-492/com.UTU I/System.out: ****map clicked. 
07-27 11:51:54.031 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:54.101 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:54.101 492-492/com.UTU I/System.out: ****map clicked. 
07-27 11:51:54.211 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 0 
07-27 11:51:54.271 492-492/com.UTU D/ViewRootImpl: ViewPostImeInputStage processPointer 1 
07-27 11:51:54.271 492-492/com.UTU I/System.out: ****map clicked. 
+0

ありがとう、ありがとうございます –

関連する問題