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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:20:23+00:00 2026-06-18T13:20:23+00:00

Hello i’ve build already smartphone apps but now i’m starting working on a project

  • 0

Hello i’ve build already smartphone apps but now i’m starting working on a project to make my app compatible with tablets. Now i’m using fragments this is my first using fragments so thats why i need your advice, please help or give me examples with my code. Many thanks already

my code my “news” class:

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Nieuws extends FragmentActivity{

    // Connection detector
    //ConnectionDetector cd;

    // Alert dialog manager
    //AlertDialogManager alert = new AlertDialogManager();

    // Progress Dialog
    //private ProgressDialog pDialog;

    private static String URL = "http://localhost/fetch.php?page=2&android";

    // JSON Node namen
    static final String TAG_DATA = "data";
    static final String TAG_ID = "id";
    static final String TAG_CATEGORY = "category";
    static final String TAG_TITLE = "title";
    static final String TAG_AUTHOR = "author";
    static final String TAG_DATE = "date";
    static final String TAG_INTRODUCTION = "introduction";
    static final String TAG_CONTENT = "content";
    static final String TAG_THUMBNAIL = "thumbnail";
    static final String TAG_MEDIA = "media";
    static final String TAG_SOURCE = "source";
    static final String TAG_LINKEDMEDIA = "linkedMedia"; //array waarin de plaatjes zitten*/

    // Nieuws JSONArray
    JSONArray newsArray;

    ListView list;
    LazyAdapter adapter;

    private PullToRefreshListView mPullRefreshListView;

    ArrayList<HashMap<String, String>> newsList; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nieuws);
    //list=(ListView)findViewById(R.id.list);
    mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);

/*    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();

    StartFragment myFragment = new StartFragment();
    ft.add(R.id.myFragment, myFragment);
    ft.commit();*/

    /*  cd = new ConnectionDetector(getApplicationContext());

    // Check for internet connection
    if (!cd.isConnectingToInternet()) {
        // Internet Connection is not present
        alert.showAlertDialog(Nieuws.this, "Internet Connectie Error", "Zorg voor een werkende internet connectie", false);
        // stop executing code by return
        return;
    }*/

    // Set a listener to be invoked when the list should be refreshed.
    mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
        @Override
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {

            // Do work to refresh the list here.
            new GetJSONData().execute();
        }
    });

    //Async 
    new GetJSONData().execute();

}


class GetJSONData extends AsyncTask<Void, Void, ArrayList<HashMap<String, String>>>{

    /**
     * Before starting background thread Show Progress Dialog
     */
    @Override
    protected void onPreExecute(){
        super.onPreExecute();
        //pDialog = new ProgressDialog(Nieuws.this);
        //pDialog.setMessage("Nieuws laden ...");
        //pDialog.setIndeterminate(false);
        //pDialog.setCancelable(false);
        //pDialog.show();   
    }

    /**
     * Get de json
     */
@Override
protected ArrayList<HashMap<String, String>> doInBackground(Void... arg0) {
    // Hashmap voor listView
    final ArrayList<HashMap<String, String>> newsList = new ArrayList<HashMap<String, String>>();

    // Maak een JSON Parser instance
    JSONParser jParser = new JSONParser();

    // Pakt JSON string uit URL
    JSONObject json = jParser.getJSONFromUrl(URL);


    try{
        // Pakt de Array van Nieuwsartikelen
        newsArray = json.getJSONArray(TAG_DATA);

        // Loop door alle Nieuwsartikels
        for(int i=0; i < newsArray.length(); i++){
            JSONObject c = newsArray.getJSONObject(i);

            // Het plaatsen van elk json item in variabele
            String title = c.getString(TAG_TITLE);
            String content = c.getString(TAG_CONTENT);
            String date = c.getString(TAG_DATE);
            //String introduction = c.getString(TAG_INTRODUCTION);
            String thumbnail = c.getString(TAG_THUMBNAIL);
            String linkedMedia = c.getString(TAG_LINKEDMEDIA);

            //String thumbnailName = c.getString(TAG_THUMBNAIL);
            //String thumbnailFormat = "http://iappministrator.com/mooiwark/media/%s";
            //String thumbnail = String.format(thumbnailFormat, thumbnailName);

            // maak een nieuwe HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // voeg elk item child node in de Hashmap -> value
            map.put(TAG_TITLE, title);
            map.put(TAG_CONTENT, content);
            map.put(TAG_DATE, date);
            //map.put(TAG_INTRODUCTION, introduction);
            map.put(TAG_THUMBNAIL, thumbnail);
            map.put(TAG_LINKEDMEDIA, linkedMedia);


            // voeg de HashList toe aan ArrayList
            newsList.add(map);

             // Click event for single list row
           mPullRefreshListView.setOnItemClickListener(new OnItemClickListener(){
            //list.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {

                    HashMap<String, String> map = newsList.get(position - 1);
                     Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);

                    //Intent in = new Intent(SingleMenuItemActivity.this, org.scout.android.library.LibraryDetail.class);
                    in.putExtra(TAG_TITLE, map.get(TAG_TITLE));
                    in.putExtra(TAG_CONTENT, map.get(TAG_CONTENT));                         
                    in.putExtra(TAG_DATE, map.get(TAG_DATE));
                    //in.putExtra(TAG_INTRODUCTION, map.get(TAG_INTRODUCTION));
                    in.putExtra(TAG_THUMBNAIL, map.get(TAG_THUMBNAIL));
                    in.putExtra(TAG_LINKEDMEDIA, map.get(TAG_LINKEDMEDIA));

                    startActivity(in);

                }
            });
        }
    } catch(JSONException e){
        e.printStackTrace();
    }
    return newsList;
}
@Override
protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

    //De items worden ingeladen
    adapter=new LazyAdapter(Nieuws.this, result, R.layout.list_row, 
            new String[]{TAG_TITLE, TAG_CONTENT, TAG_DATE, TAG_THUMBNAIL}, new int[] {
            R.id.title, R.id.subtitle, R.id.date, R.id.list_image});   //TAG_INTRODUCTION mist nog 
    //list.setAdapter(adapter);
    mPullRefreshListView.setAdapter(adapter);

    // dismiss the dialog after getting all deelnemers
    //pDialog.dismiss();

    mPullRefreshListView.onRefreshComplete();

    super.onPostExecute(result);
        }
    }
}

in this activity it would normally load the content when on click. this class is the one which i’ve tried to turn into a fragments class
“SingleMenuItemActivity” class :

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class SingleMenuItemActivity  extends Fragment {

    // JSON node keys
    private static final String TAG_TITLE = "title";
    private static final String TAG_CONTENT = "content";
    private static final String TAG_DATE = "date";
    private static final String TAG_LINKEDMEDIA = "linkedMedia";
    //private static final String TAG_THUMBNAIL = "thumbnail";

    // Connection detector
    ConnectionDetector cd;

    // Alert dialog manager
    AlertDialogManager alert = new AlertDialogManager();

    /*@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);*/
   View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.single_list_item, container, false);

        return view;

        cd = new ConnectionDetector(getActivity().getApplicationContext());

        // Check for internet connection
        if (!cd.isConnectingToInternet()) {
            // Internet Connection is not present
            alert.showAlertDialog(getActivity(), "Internet Connectie Error", "Zorg voor een werkende internet connectie", false);
            // stop executing code by return
            return;
        }

        // getting intent data

        Intent in = getIntent().getExtras();

        //final String image_url = in.getStringExtra(TAG_THUMBNAIL);
        final String image_url = in.getStringExtra(TAG_LINKEDMEDIA);

        ImageView imgv = (ImageView) getView().findViewById(R.id.images_label);
        ImageLoader imageLoader = new ImageLoader(getActivity().getApplicationContext());
        imageLoader.DisplayImage(image_url, imgv);

        // Get JSON values from previous intent
        String title = in.getStringExtra(TAG_TITLE);
        String date = in.getStringExtra(TAG_DATE);
        String message = in.getStringExtra(TAG_CONTENT);
        //String images = in.getStringExtra(TAG_IMAGES);
        //Bitmap bitmap = in.getParcelableExtra(TAG_IMAGES);
        //ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);

        // Displaying all values on the screen
        TextView lblTitle = (TextView)getView().findViewById(R.id.title_label);
        TextView lblDate = (TextView) getView().findViewById(R.id.date_label);
        TextView lblMessage = (TextView) getView().findViewById(R.id.message_label);
        //ImageView lblImages = (ImageView) findViewById(R.id.images_label); 
        //TextView lblImages = (TextView) findViewbyId(R.id.images_label);



        // loader image
        //int loader = R.drawable.loader;
        System.out.println("Ja en nu werkt het niet meer");

        // image url
        //String image_url = "http://d24w6bsrhbeh9d.cloudfront.net/photo/5614379_460s.jpg";

       //ImageLoader imgLoader = new ImageLoader(getApplicationContext());
        //-imgLoader.DisplayImage(song.get(CustomizedListView.TAG_IMAGES), lblImages);
        System.out.println("Error? haha bam jammer dan:");
       //imgLoader.DisplayImage(images, lblImages);
        //System.out.println("Plaatjes?:"+ images);

        lblTitle.setText(title);
        lblDate.setText(date);
        lblMessage.setText(message);

        //lblImages.setImageURI(Uri.parse(images));

        //ImageLoader imageLoader = new ImageLoader(getApplicationContext());
        //imageLoader.DisplayImage(images,lblImages);

        //lblImages.setImageResource(images);
        //imageLoader.displayImage(images);
        //lblImages.setImageBitmap(bitmap);
        //lblImages.setImageResource(R.drawable.bitmap);
        //lblImages.setImageResource(images);
        /*if (d instanceof BitmapDrawable) {
            Bitmap bm = ((BitmapDrawable)d).getBitmap();
            //Maybe more code here?
            lblImages.setImageBitmap(bm);
    }*/
        //lblImages.setImageResource(images);
        //lblImages.DisplayImage(images);
        //lblImages.DisplayImage(images);
    }
}

Now i’m getting to the part which i don’t understand my Intent in = getIntent() doesn’t work i get errors. Can someone guide me on turning from code form a activity to a fragment many thanks already

Screenshot:
enter image description here

Left the “news class” right “SingleMenuItemActivity”

It’s going wrong when i click the onclick in the class on the left.

  • 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-18T13:20:24+00:00Added an answer on June 18, 2026 at 1:20 pm

    First of all i advise you to use a ListFragment for your list and define a listerner for onclick event (this listener could be your Nieuws activity).

    Then you will need to have 2 layouts. The classic one with one fragment:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/onepane_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical" >
    </LinearLayout>
    

    and the other one with two fragment:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:id="@+id/towpane_layout">
        <fragment android:id="@+id/listFragment"
                  android:layout_height="fill_parent"
                  android:name="com.example.MyListFragment"
                  android:layout_width="400dp"
                  android:layout_marginRight="10dp"/>
        <fragment android:id="@+id/displayFragment"
                  android:layout_height="fill_parent"
                  android:name="com.example.MyDisplayFragment"
                  android:layout_width="fill_parent" />
    </LinearLayout>
    

    in your Nieuws Activity you will check if the layout loaded has two fragments if not you will load the ListFragment using the fragment manager

    //Check that the activity is not using the layout with fragment;
            if(findViewById(R.id.onepane_layout) != null) {
                if (savedInstanceState != null) {
                    return;
                }
                MyListFragment lFragment = new MyListFragment ();
    
                // In case this activity was started with special instructions from an Intent,
                // pass the Intent's extras to the fragment as arguments
                lFragment .setArguments(getIntent().getExtras());
    
                 getFragmentManager().beginTransaction()
                 .add(R.id.onepane_layout, lFragment ).commit();
            }
    

    Then in your on item selection method you need again to load the display fragment if you are in one pane mode:

    MyDisplayFragment dispFrag = (MyDisplayFragment)
                    getSupportFragmentManager().findFragmentById(R.id.displayFragment);
    
    
    
     if (dispFrag != null) {
            // If display frag is available, we're in two-pane layout...
    
            // Call a method in the DisplayFragment to update its content
            dispFrag.updateView(position);
    
        } else {
            // If the frag is not available, we're in the one-pane layout and must swap frags...
    
            // Create fragment and give it an argument for the selected article
            MyDisplayFragment newFragment = new MyDisplayFragment ();
            Bundle args = new Bundle();
            args.putInt(MyDisplayFragment.ARG_POSITION, position);
            newFragment.setArguments(args);
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    
            // Replace whatever is in the fragment_container view with this fragment,
            // and add the transaction to the back stack so the user can navigate back
            transaction.replace(R.id.fragment_container, newFragment);
            transaction.addToBackStack(null);
    
            // Commit the transaction
            transaction.commit();
        }
    

    There is more to explain but this is the basics. You may need to check these two usefull links:
    http://developer.android.com/training/multiscreen/adaptui.html

    http://developer.android.com/training/basics/fragments/fragment-ui.html

    You will need also to handle screen rotation.

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

Sidebar

Related Questions

hello all i am working on a project in which i have a webpage
Hello all I'm working on a little project where I'm adding controls to a
Hello! I've been programming for a long time but just started developing for android,
Hello all I am working on javascript jquery and svg.I want to ask a
Hello all I am working on html and javascript.And I am going to ask
Hello i want to make something on classes i want to do a super
Hello again; i need to show X,Y,Risk in ListBoxes. But i can not do
hello i'm building a wpf app with data grids, the pattern is model view
hello all i am new to iphone development i am working on a application
Hello I am trying to make an invisible button (still functional and clickable), because

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.