im quite new to java coding in android studio, can anyone help ? the click work however it going to the main activity back. it does not go to the wanted activity.
here is my main activity java
package com.example.dashboard;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
public CardView draftCard, cardsCard, todoCard, moneyCard, linkedinCard;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
//definingcards
draftCard = findViewById(R.id.draftCard);
cardsCard = findViewById(R.id.cardsCard);
moneyCard = findViewById(R.id.moneyCard);
todoCard = findViewById(R.id.todoCard);
linkedinCard = findViewById(R.id.linkedinCard);
//addingclicklistener
draftCard.setOnClickListener(this);
cardsCard.setOnClickListener(this);
moneyCard.setOnClickListener(this);
todoCard.setOnClickListener(this);
linkedinCard.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent i = getIntent();
switch (v.getId()) {
case R.id.draftCard:
new Intent(this, draftcard.class);
startActivity(i);
break;
case R.id.cardsCard:
new Intent(this, cardscard.class);
startActivity(i);
break;
case R.id.moneyCard:
new Intent(this, moneycard.class);
startActivity(i);
break;
case R.id.todoCard:
new Intent(this, todocard.class);
startActivity(i);
break;
case R.id.linkedinCard:
new Intent(this, linkedincard.class);
startActivity(i);
break;
default:break;
}
}
}
really appreciate, as i hardly thinking why it was not working, as i thought everything was good.
here is my stack trace
2021-01-27 22:30:34.983 6206-6206/? I/ample.dashboar: Not late-enabling -Xcheck:jni (already on)
2021-01-27 22:30:35.017 6206-6206/? W/ample.dashboar: Unexpected CPU variant for X86 using defaults: x86
2021-01-27 22:30:35.285 6206-6206/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2021-01-27 22:30:35.290 6206-6206/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2021-01-27 22:30:35.407 6206-6206/com.example.dashboard W/ample.dashboar: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2021-01-27 22:30:35.436 6206-6206/com.example.dashboard D/OpenGLRenderer: HWUI GL Pipeline
2021-01-27 22:30:35.499 6206-6250/com.example.dashboard D/HostConnection: HostConnection::get() New Host Connection established 0xe4f1e230, tid 6250
2021-01-27 22:30:35.506 6206-6250/com.example.dashboard D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2
2021-01-27 22:30:35.517 6206-6250/com.example.dashboard I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-01-27 22:30:35.517 6206-6250/com.example.dashboard I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2021-01-27 22:30:35.517 6206-6250/com.example.dashboard I/OpenGLRenderer: Initialized EGL, version 1.4
2021-01-27 22:30:35.518 6206-6250/com.example.dashboard D/OpenGLRenderer: Swap behavior 1
2021-01-27 22:30:35.520 6206-6250/com.example.dashboard W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-01-27 22:30:35.520 6206-6250/com.example.dashboard D/OpenGLRenderer: Swap behavior 0
2021-01-27 22:30:35.576 6206-6250/com.example.dashboard D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2021-01-27 22:30:35.576 6206-6250/com.example.dashboard D/EGL_emulation: eglCreateContext: 0xe4f05120: maj 2 min 0 rcv 2
2021-01-27 22:30:35.643 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:35.685 6206-6250/com.example.dashboard D/HostConnection: createUnique: call
2021-01-27 22:30:35.685 6206-6250/com.example.dashboard D/HostConnection: HostConnection::get() New Host Connection established 0xe4f1e4b0, tid 6250
2021-01-27 22:30:35.688 6206-6250/com.example.dashboard D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2
2021-01-27 22:30:35.689 6206-6250/com.example.dashboard E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1
2021-01-27 22:30:35.698 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:38.339 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@fa80e4f
2021-01-27 22:30:38.555 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:38.676 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:38.696 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:38.758 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:39.141 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:40.043 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:30:47.748 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@c41b27d
2021-01-27 22:30:47.930 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:01.288 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@4ae335d
2021-01-27 22:31:01.460 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:07.108 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@5aca43d
2021-01-27 22:31:07.264 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:10.552 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@ef5051d
2021-01-27 22:31:10.702 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:13.642 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@c3f55fd
2021-01-27 22:31:13.812 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:14.911 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@54396dd
2021-01-27 22:31:15.090 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:15.326 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:15.655 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:16.577 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
2021-01-27 22:31:18.463 6206-6206/com.example.dashboard W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@c23d1b2
2021-01-27 22:31:18.590 6206-6250/com.example.dashboard D/EGL_emulation: eglMakeCurrent: 0xe4f05120: ver 2 0 (tinfo 0xe4f03660)
question from:
https://stackoverflow.com/questions/65921235/adding-onclicklistener-on-cardview 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…