Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:25:49+00:00 2026-05-27T07:25:49+00:00

I have an app with 10 list items.All the items onClick have the same

  • 0

I have an app with 10 list items.All the items onClick have the same layout between them.I have created a new class for every item and using a switch method to move to every activity.Is there any way to make it more simple( and dont have 10 classes but less)?Thanks

mylist.add(map);

            map = new HashMap<String, Object>();
            map.put("name", "aa");
            map.put("address", "aaa");
            map.put("address3", R.drawable.im1);

            mylist.add(map);// i m adding 10 items like this here


            ListAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.row,
                        new String[] {"name", "address","address3"}, new int[] {R.id.TextView1, R.id.TextView2,R.id.imgdiadromes});
            listcafe.setAdapter(mSchedule);



            listcafe.setOnItemClickListener(new OnItemClickListener() {
             public void onItemClick(AdapterView<?> parent, View view,
                      int position, long id) {
                    switch( position )
                    {
                       case 0:    
                        Intent newActivity = new Intent(diadromes.this, monte.class);
                        startActivity(newActivity);
                        break;
                    case 1:    
                        Intent newActivity1 = new Intent(diadromes.this, diadromestherisos.class);
                        startActivity(newActivity1);
                        break;

//and i have 8 more cases here

The class mothe.class and the diadromestherisos.class are exactly the same,i m getting the same content view and i m only changing the text and the images(from .setText and.setImageResource).Hope my problem is understandable!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:25:50+00:00Added an answer on May 27, 2026 at 7:25 am

    If they’re all the same except for the text and image, then you really only need 1 Activity class to handle all 10 cases. What you can do in your switch is populate a Bundle with the ids of the text resource and the drawable resource and pass that into the activity.

    So your switch would look like:

    switch(position){
      case 0: 
          Intent newActivity = new Intent(diadromes.this, YourNewActivity.class);
          newActivity.putExtra("TXT_RESOURCE",R.string.your_text_resource_id);
          newActivity.putExtra("IMG_RESOURCE",R.drawable.your_img_resource_id);
          startActivity(newActivity);
          break;
       case 1:
          //similar to above, but populate with the different resource ids
    }
    

    then in your YourNewActivity class, you need to read in the extras and use them to populate your UI:

    public void onCreate(Bundle savedInstanceState){
       Bundle extras = getIntent().getExtras();
       int textResourceId = extras.getInt("TXT_RESOURCE");
       int imgResourceId = extras.getInt("IMG_RESOURCE");
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of items, instances of a Item class saved in a
I have an app that has a list of items. My customer prefers to
On my rails app I have a list of items (like a task list)
I have a visual list of items like this: http://jsfiddle.net/viatropos/XCe3T/1/ In the real app,
The app I am creating shows users a list of items which are all
I have a simple rails app the displays a list of items and i
I have a jQuery app where the user can add items to a list
I have a list of items in my web app. Currently these have a
I have an iPhone app that utilizes TableView to list tagged items that the
I have an android app that displays a list of items in a Custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.