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

  • SEARCH
  • Home
  • 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 7771273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:36:40+00:00 2026-06-01T16:36:40+00:00

I have a problem with my Android Application. In my Application I have a

  • 0

I have a problem with my Android Application. In my Application I have a ListView and each item in it contains some text and an image. I want each of the items to open up a different layout. These layouts will just contain some simple text. But I can’t seem to find out how to get my items (in the ListView) to open different layouts. Please help!

package com.xxxxx;

import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ParseException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends ListActivity {
    private LayoutInflater mInflater;
    private Vector<RowData> data;
    RowData rd;

    static final String[] title = new String[] {
        "text", 
        "text", 
        "text",
        "text",
        "text",
    };

    static final String[] detail = new String[] {
        "text",
        "text",
        "text",
        "text",
        "text",
    };

    private Integer[] imgid = {
        R.drawable.image1,
        R.drawable.image2,
        R.drawable.image3,
        R.drawable.image4,
        R.drawable.image5,
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mInflater = (LayoutInflater) getSystemService(
        Activity.LAYOUT_INFLATER_SERVICE);
        data = new Vector<RowData>();
        for(int i=0;i<title.length;i++){

            try {
            rd = new RowData(i,title[i],detail[i]);
            } catch (ParseException e) {
            e.printStackTrace();
            }
            data.add(rd);
        }
        CustomAdapter adapter = new CustomAdapter(this, R.layout.list, R.id.title, data);
        setListAdapter(adapter);
        getListView().setTextFilterEnabled(true);
    }
    public void onListItemClick(ListView parent, View v, int position, long id) {           
        RowData item = (RowData) getListAdapter().getItem(position);
        Intent intent = new Intent(this, NewActivity.class);
        intent.putExtra("id", item.mId);
        startActivity(intent);
    }
}

private class RowData {
    protected int mId;
    protected String mTitle;
    protected String mDetail;
    RowData(int id,String title,String detail){
        mId=id;
        mTitle = title;
        mDetail=detail;
    }

    @Override
    public String toString() {
        return mId+" "+mTitle+" "+mDetail;
    }
}

private class CustomAdapter extends ArrayAdapter<RowData> {

    public CustomAdapter(Context context, int resource, 
        int textViewResourceId, List<RowData> objects) { 

        super(context, resource, textViewResourceId, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {   

        ViewHolder holder = null;
        TextView title = null;
        TextView detail = null;
        ImageView i11=null;
        RowData rowData= getItem(position);
        if(null == convertView){
            convertView = mInflater.inflate(R.layout.list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        title = holder.gettitle();
        title.setText(rowData.mTitle);
        detail = holder.getdetail();
        detail.setText(rowData.mDetail);                                                     

        i11=holder.getImage();
        i11.setImageResource(imgid[rowData.mId]);
        return convertView;
    }
}

private class ViewHolder {
    private View mRow;
    private TextView title = null;
    private TextView detail = null;
    private ImageView i11=null; 

    public ViewHolder(View row) {
        mRow = row;
    }
    public TextView gettitle() {
        if(null == title){
            title = (TextView) mRow.findViewById(R.id.title);
        }
        return title;
    }     

    public TextView getdetail() {
        if(null == detail){
            detail = (TextView) mRow.findViewById(R.id.detail);
        }
        return detail;
    }
    public ImageView getImage() {
        if(null == i11){
            i11 = (ImageView) mRow.findViewById(R.id.img);
        }
        return i11;
    }
}

Here is my New Activity

import android.app.Activity;
import android.os.Bundle;

public class NewActivity extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.poetry);

        getIntent().getExtras().getInt("id");
    }
}
  • 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-01T16:36:41+00:00Added an answer on June 1, 2026 at 4:36 pm

    you need to listen to the click on the item, so something like following before you return the convertview

    convertView.setOnClickListenere(new OnClickListener(){
          public void onClick(View v) {
             Intent intent = new Intent(MainActivity.this, NewActivity.class);
             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 problem with my Android Application. The Error occures when i want
I have some problem with Android AsyncTask. There is an Activity which contains some
I have an android application that parses some HTML, downloads an image, and displays
I have made a ListView in my android application. But the problem is that
I have a layouting problem with my android application: I have a Listview consiting
In my Android application I have used a Listview and in each element in
I have a problem in my Android application. I have a Custom ListView Adapter,
I have a problem with my android application. That application which uses the kSOAP
I have an interesting problem being reported to me from an android application I
I have a problem regarding Android App. I have created an application that download

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.