Skip to main content
deleted 29 characters in body
Source Link
200_success
  • 145.6k
  • 22
  • 191
  • 480

Here is my case I made list of items when I click at any item it should navigate to certain activity.

Here is my I am done First I set number of constants to distinguish between each activity

// constants to show activities onclick event
private static final int LOC = 0, SERVICES = 1, PRE_APPROVE = 2, CLAIMS = 3, BENEFITS = 4, QUE = 5;

Secondly I create method navigate according to this constant

private void ShowActivity(int position) {
        switch (position) {
            case LOC:
                NavigateTo(LocLacatorActivity.class);
                break;
            case SERVICES:
                NavigateTo(ServicesActivity.class);
                break;
            case PRE_APPROVE:
                NavigateTo(PreApproveActivity.class);
                break;
            case CLAIMS:
                NavigateTo(ClaimsActivity.class);
                break;
            case BENEFITS:
                NavigateTo(BenefitsActivity.class);
                break;
            case QUE:
                NavigateTo(QuestionsActivity.class);
                break;
        }
    }


 private void NavigateTo(Class mActivity) {
        Intent intent = new Intent(MainActivity.this, mActivity);
        startActivity(intent);
    }

Finally , here is how I call the method

servicesButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     ShowActivity(SERVICES);
                }
            });

isIs this good way to handle multi activity navigate ?navigation, or I can I decrease the size of my methods

thank you advance?

Here is my case I made list of items when I click at any item it should navigate to certain activity.

Here is my I am done First I set number of constants to distinguish between each activity

// constants to show activities onclick event
private static final int LOC = 0, SERVICES = 1, PRE_APPROVE = 2, CLAIMS = 3, BENEFITS = 4, QUE = 5;

Secondly I create method navigate according to this constant

private void ShowActivity(int position) {
        switch (position) {
            case LOC:
                NavigateTo(LocLacatorActivity.class);
                break;
            case SERVICES:
                NavigateTo(ServicesActivity.class);
                break;
            case PRE_APPROVE:
                NavigateTo(PreApproveActivity.class);
                break;
            case CLAIMS:
                NavigateTo(ClaimsActivity.class);
                break;
            case BENEFITS:
                NavigateTo(BenefitsActivity.class);
                break;
            case QUE:
                NavigateTo(QuestionsActivity.class);
                break;
        }
    }


 private void NavigateTo(Class mActivity) {
        Intent intent = new Intent(MainActivity.this, mActivity);
        startActivity(intent);
    }

Finally , here is how I call the method

servicesButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     ShowActivity(SERVICES);
                }
            });

is this good way to handle multi activity navigate ? or I can decrease the size of my methods

thank you advance

Here is my case I made list of items when I click at any item it should navigate to certain activity.

Here is my I am done First I set number of constants to distinguish between each activity

// constants to show activities onclick event
private static final int LOC = 0, SERVICES = 1, PRE_APPROVE = 2, CLAIMS = 3, BENEFITS = 4, QUE = 5;

Secondly I create method navigate according to this constant

private void ShowActivity(int position) {
        switch (position) {
            case LOC:
                NavigateTo(LocLacatorActivity.class);
                break;
            case SERVICES:
                NavigateTo(ServicesActivity.class);
                break;
            case PRE_APPROVE:
                NavigateTo(PreApproveActivity.class);
                break;
            case CLAIMS:
                NavigateTo(ClaimsActivity.class);
                break;
            case BENEFITS:
                NavigateTo(BenefitsActivity.class);
                break;
            case QUE:
                NavigateTo(QuestionsActivity.class);
                break;
        }
    }


 private void NavigateTo(Class mActivity) {
        Intent intent = new Intent(MainActivity.this, mActivity);
        startActivity(intent);
    }

Finally , here is how I call the method

servicesButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     ShowActivity(SERVICES);
                }
            });

Is this good way to handle multi activity navigation, or can I decrease the size of my methods?

Source Link
Mina Fawzy
  • 527
  • 2
  • 10
  • 26

Android - handle navigation to multi activities from list view

Here is my case I made list of items when I click at any item it should navigate to certain activity.

Here is my I am done First I set number of constants to distinguish between each activity

// constants to show activities onclick event
private static final int LOC = 0, SERVICES = 1, PRE_APPROVE = 2, CLAIMS = 3, BENEFITS = 4, QUE = 5;

Secondly I create method navigate according to this constant

private void ShowActivity(int position) {
        switch (position) {
            case LOC:
                NavigateTo(LocLacatorActivity.class);
                break;
            case SERVICES:
                NavigateTo(ServicesActivity.class);
                break;
            case PRE_APPROVE:
                NavigateTo(PreApproveActivity.class);
                break;
            case CLAIMS:
                NavigateTo(ClaimsActivity.class);
                break;
            case BENEFITS:
                NavigateTo(BenefitsActivity.class);
                break;
            case QUE:
                NavigateTo(QuestionsActivity.class);
                break;
        }
    }


 private void NavigateTo(Class mActivity) {
        Intent intent = new Intent(MainActivity.this, mActivity);
        startActivity(intent);
    }

Finally , here is how I call the method

servicesButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     ShowActivity(SERVICES);
                }
            });

is this good way to handle multi activity navigate ? or I can decrease the size of my methods

thank you advance