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 8988361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:59:59+00:00 2026-06-15T21:59:59+00:00

I have 16 items in listView layout.How to let every item jump to another

  • 0

I have 16 items in listView layout.How to let every item jump to another activity.I have tried this code ,but nothing happen:(

this is GroupActivity.java

package com.test.listview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class GroupActivity extends Activity{
    private ListView listView;
    private ListViewAdapter listViewAdapter;
    private List<Map<String, Object>> listItems;  
    protected SharedPreferences group_sp;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.group);

        listView=(ListView)findViewById(R.id.group1_list);
        listItems=getlistItems();
        listViewAdapter=new ListViewAdapter(this, listItems);
        listView.setAdapter(listViewAdapter);
        listView.setTextFilterEnabled(true);

        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
                Log.i("mm", " onItemClick ");
                Intent intent=new Intent();
                switch(position){
                case 0:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 1:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 2:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 3:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 4:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 5:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 6:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 7:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 8:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 9:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 10:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 11:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 12:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 13:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 14:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                case 15:
                    intent.setClass(getApplicationContext(), ListViewGroup.class);
                    GroupActivity.this.startActivity(intent);
                    break;
                }

            }

        });
    }

    private List<Map<String, Object>> getlistItems() {
         List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();
         for(int i = 1; i<=16; i++) { 
             Map<String, Object> map = new HashMap<String, Object>();
             map.put("imageButton", R.drawable.goff1);                
             map.put("textView", "Group"+i);          
             map.put("imageView",R.drawable.arrow1);    
             listItems.add(map);   
        }      
         return listItems;   
    }
}

this is the code from Adapter:

package com.test.listview;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {
    private Context context;                         
    private List<Map<String,Object>> listItems;      //group list
    private LayoutInflater layoutInflater;           //View container
    protected SharedPreferences group_sp;

    /**Custom list control set*/
    public final class ListItemView{
        public ImageButton imageButton;
        public TextView textView;
        public ImageView imageView;
    }

    public ListViewAdapter(Context context,List<Map<String,Object>> listItems){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);//创建视图容器设置上下文
        this.listItems=listItems;
    }

    public int getCount() {
        return listItems.size();
    }

    public Object getItem(int position) {
        return listItems.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    /**list settings*/
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
            convertView=layoutInflater.inflate(R.layout.group_list, null);
            //get space object
            final ImageButton imageButton=(ImageButton)convertView.findViewById(R.id.goff1);    
            imageButton.setBackgroundResource(R.drawable.goff1);
            imageButton.setOnClickListener(new View.OnClickListener() {
                boolean flag=true;
                public void onClick(View v) {
                    if(flag){
                        imageButton.setBackgroundResource(R.drawable.gon1);
                        flag=false;
                    }else{
                        imageButton.setBackgroundResource(R.drawable.goff1);
                        flag=true;
                    }    

                }


            });
            TextView textView=(TextView)convertView.findViewById(R.id.title);
            ImageView imageView=(ImageView)convertView.findViewById(R.id.right_image);
//            imageView.setOnClickListener(new View.OnClickListener() {
//                
//                @Override
//                public void onClick(View v) {   
//                    Intent intent=new Intent(); 
//                    intent.setClass(context, ListViewGroup.class); 
//                    context.startActivity(intent);
//                }
//            });

            //padding image and word
            imageButton.setBackgroundResource((Integer)listItems.get(position).get("imageButton"));
            textView.setText((String)listItems.get(position).get("textView"));
            imageView.setBackgroundResource((Integer)listItems.get(position).get("imageView"));

        //addListener(convertView);
        return convertView;
    }

}

Could anyone help me out this?thank you.

  • 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-06-15T22:00:00+00:00Added an answer on June 15, 2026 at 10:00 pm

    if you want to start same activity on onItemClick then no need to use switch case for starting new activity on every row click just change your code as:

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view
                                                    , int position,long id) {
          Log.i("mm", " onItemClick ");
          Intent intent=new Intent(GroupActivity.this,ListViewGroup.class);
    
          GroupActivity.this.startActivity(intent);
        }
    
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with a custom layout for the rows (list items) and
I have a listview. By default, all items have itemInvoke and single-selection enabled. But
I have a ListView with SimpleCursorAdapter. The layout was using a LinearLayout, but when
I have a listactivity which contains a listview. i want to show another layout
I have created a page with horizontal layout listview with enough items added to
Hi i have a tab activity which show a list of items (ListView) .
The objective is to have different layout for items in a ListView depending on
I have a GridView that displays items, each item is a ListView. the problem
I have listview control.There is an option to remove selected items.After the user removes
I have a ListView that shows around 300 items. When something is changed and

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.