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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:36:05+00:00 2026-05-26T08:36:05+00:00

here is my layuout main.xml ; <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent>

  • 0

here is my layuout main.xml ;

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1" android:visibility="visible" android:clickable="true"/>

</LinearLayout>

Here is the MainActivity which extends ListActivity;

 public class MainActivity extends ListActivity {
        private final List<SpinnerEntry> spinnerContent = new LinkedList<SpinnerEntry>();
        private ListView contactListView;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            contactListView=getListView();
queryAllRawContacts();
registerForContextMenu(getListView());

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Intent i = new Intent(this, ContactDetailsActivity.class);
        i.putExtra("hello", id);
        // Activity returns an result if called with startActivityForResult

        startActivity(i);
    }

private void queryAllRawContacts() {


        final String[] projection = new String[] {
                RawContacts.CONTACT_ID,                 // the contact id column
                RawContacts.DELETED                     // column if this contact is deleted
        };

        final Cursor rawContacts = managedQuery(
                RawContacts.CONTENT_URI,                // the uri for raw contact provider
                projection, 
                null,                                   // selection = null, retrieve all entries
                null,                                   // not required because selection does not contain parameters
                null);                                  // do not order

        final int contactIdColumnIndex = rawContacts.getColumnIndex(RawContacts.CONTACT_ID);
        final int deletedColumnIndex = rawContacts.getColumnIndex(RawContacts.DELETED);

        spinnerContent.clear();
        if(rawContacts.moveToFirst()) {                 // move the cursor to the first entry
            while(!rawContacts.isAfterLast()) {         // still a valid entry left?
                final int contactId = rawContacts.getInt(contactIdColumnIndex);
                final boolean deleted = (rawContacts.getInt(deletedColumnIndex) == 1);
                if(!deleted) {
                    spinnerContent.add(queryDetailsForContactSpinnerEntry(contactId));
                }
                rawContacts.moveToNext();               // move to the next entry
            }
        }

        rawContacts.close();
        final ContactsSpinnerAdapater adapter = new ContactsSpinnerAdapater(spinnerContent, this);
        contactListView.setAdapter(adapter);
    }

And here is my customadapter class called ContactsSpinnerAdapater ;

public class ContactsSpinnerAdapater extends BaseAdapter implements
        SpinnerAdapter{
    private final List<SpinnerEntry> content;
    private final Activity activity;

    public ContactsSpinnerAdapater(List<SpinnerEntry> content,
            Activity activity) {
        super();
        this.content = content;
        this.activity = activity;
    }

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

    public SpinnerEntry getItem(int position) {
        return content.get(position);
    }

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

    public View getView(int position, View convertView,
            ViewGroup parent) {
        final LayoutInflater inflater = activity.getLayoutInflater();   // default layout inflater
        final View spinnerEntry = inflater.inflate(
                R.layout.row, null);                // initialize the layout from xml
        final TextView contactName = (TextView) spinnerEntry
                .findViewById(R.id.cName);
        final ImageView contactImage = (ImageView) spinnerEntry
                .findViewById(R.id.userIcon);
        final SpinnerEntry currentEntry = content.get(position);    
        contactName.setText(currentEntry.getContactName());
        contactImage.setImageBitmap(currentEntry.getContactPhoto());
        spinnerEntry.setOnClickListener(new OnClickListener(){


            public void onClick(View arg0) {
                // TODO Auto-generated method stub

            }});
        return spinnerEntry;
    }




}

The problem is that whatever I tried I could not start the ContacDetailsActivity intent when any of the list item is clicked. Basically, the listener some how is not activated. So could you please have a look at the code and tell me where I am missing it?

  • 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-26T08:36:05+00:00Added an answer on May 26, 2026 at 8:36 am

    You’ve put your intent starting code in the wrong place. You need to put this code:

        super.onListItemClick(l, v, position, id);
        Intent i = new Intent(this, ContactDetailsActivity.class);
        i.putExtra("hello", id);
        // Activity returns an result if called with startActivityForResult
    
        startActivity(i);
    

    in your getView method in your adapter like this

    public View getView(int position, View convertView,
            ViewGroup parent) {
        final int myFinalPosition = position;
        final LayoutInflater inflater = activity.getLayoutInflater();   // default layout inflater
        final View spinnerEntry = inflater.inflate(
                R.layout.row, null);                // initialize the layout from xml
        final TextView contactName = (TextView) spinnerEntry
                .findViewById(R.id.cName);
        final ImageView contactImage = (ImageView) spinnerEntry
                .findViewById(R.id.userIcon);
        final SpinnerEntry currentEntry = content.get(position);    
        contactName.setText(currentEntry.getContactName());
        contactImage.setImageBitmap(currentEntry.getContactPhoto());
        spinnerEntry.setOnClickListener(new OnClickListener(){
    
    
            public void onClick(View arg0) {
              Intent i = new Intent(activity, ContactDetailsActivity.class);
              i.putExtra("hello", getItemId(myFinalPosition));
              // Activity returns an result if called with startActivityForResult
    
              activity.startActivity(i);
    
            }});
        return spinnerEntry;
    }
    

    Note the use of the activity variable to start up the intent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new to java and android. I need some help with my main.xml
Here is my code, which takes two version identifiers in the form 1, 5,
This is my main.xml that I use, and the two images in the myImage_Main
Here is the directory layout that was installed with Leopard. What is the A
I have a mockup layout for something here . Essentially there are sections, columns
Here is the scenario: I have two asp pages. a.aspx is layout and b.aspx
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior

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.