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" />
あなたはonClickListenerてみましたやった結果()?? –
おそらく、android:focusable = "false" linearLayoutとclickable = trueの両方を削除しようとしました。 – Chol
@Vivekはいいいえ運がよろしいですか?アドバイスありがとうございます。まだ動作しません。 –