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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:54:29+00:00 2026-06-14T09:54:29+00:00

Hi I have the following code and 2 questions in the code Q1 and

  • 0

Hi I have the following code and 2 questions in the code Q1 and Q2

Q1) I have read on this site that you can’t create a new Activity from inside a fragment, so if I’m inside a fragment and would like to do

Intent intent = new Intent(this, DetailActivity.class);
startActivity(intent);

how do I do it?


Q2)
Also it seems like I don’t get into my onListItemClick, am I’m doing something wrong here, is the OnListItemsClick missplaced or what?

I have the file ActionBarMain.java that creates a new fragment Fragment1.java bellow

//ActionbarMain.java

        fram1 = new FragMent1();
        fragMentTra.addToBackStack(null);
        fragMentTra = getFragmentManager().beginTransaction().add(rl.getId(), fram1, "fram1");


//Fragment1.java
    import android.app.Fragment;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;

    public class FragMent1 extends Fragment {

    private String[] bookNames;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        ListView listView = new ListView(getActivity());
        ArrayAdapter<String> array = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1);

        bookNames= bookNames();



        for (String str : bookNames)
            array.add(str);
        listView.setAdapter(array);
        return listView;
    }

    private String[] bookNames(){
        SimpleBookManager.getSimpleBookManager().count();
        bookNames = new String[SimpleBookManager.getSimpleBookManager().count()]; 
        for(int i=0; i < SimpleBookManager.getSimpleBookManager().count(); i++){
            bookNames[i]= SimpleBookManager.getSimpleBookManager().getBook(i).getTitle();
        }
        return bookNames;
    }

    public void onListItemClick(ListView l, View v, int position, long id) {
        //Q1)Nothing happens here nothing is printed out and I get no errors when I click on
        //an Item in the list, its like it don't come here, why?
        Log.d("test", SimpleBookManager.getSimpleBookManager().getBook(position).getTitle());
        Log.d("test", "jje");

        //Q2)Call the DetailActivity.java how to achive this since I'm inside a fragment?   
    }
}
  • 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-14T09:54:31+00:00Added an answer on June 14, 2026 at 9:54 am

    Why don’t you use a ListFragment ?

    Something like this:

    public class ListFragment extends android.support.v4.app.ListFragment {
        /*
         * (non-Javadoc)
         * 
         * @see android.support.v4.app.Fragment#onCreate(android.os.Bundle)
         */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
        }
    
        /*
         * (non-Javadoc)
         * 
         * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
         */
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                    "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                    "Linux", "OS/2" };
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_1, values);
            setListAdapter(adapter);
    
        }
    
        /*
         * (non-Javadoc)
         * 
         * @see
         * android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView
         * , android.view.View, int, long)
         */
        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
            String item = (String) getListAdapter().getItem(position);
            Intent intent = new Intent(getActivity().getApplicationContext(),
                        DetailActivity.class);
                intent.putExtra("value", item);
                startActivity(intent);
            }
    
        }
    } //END OF CLASS
    //END OF FILE
    

    The above code works for me.

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

Sidebar

Related Questions

A quick questions about sessions, I have a session with the following code <?php
This is a beginner level question for asp.net MVC I have the following code
Follow up to this question . I have the following code: string[] names =
This should be a pretty straightforward question. I have the following code, which forms
This is an ANSI C question. I have the following code. #include <stdio.h> #include
This is a code review question more then anything. I have the following problem:
Before anything, I have read both this and this questions to solve the problem
I have the following sample code. class bar is derived from the base class
I have read thru a number of other questions similar to this one -
I've read similar questions on SO but can't seem to figure out this issue,

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.