Android Open Source - Planets Planet Fragment

From Project

Back to project page Planets.


The source code is released under:

Apache License

If you think the Android project Planets listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.andrewq.planets;
/*from   ww w  .  j  a v  a  2 s. c om*/

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class PlanetFragment extends Fragment {
  private Button button;
  private TextView titleView;
  private TextView descriptionText;
  private TextView bodyText;
  private ImageView imageView;
  private String url;
  private String title;
  private String[] planet;
  private String description;
  private String body;
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    button = (Button) view.findViewById(;
    titleView  = (TextView)view.findViewById(;
    descriptionText  = (TextView)view.findViewById(;
    bodyText  = (TextView)view.findViewById(;
    imageView = (ImageView)view.findViewById(;
    Bundle args = getArguments();

    planet = args.getStringArray(MainActivity.DESCRIPTIONS);
    title = args.getString(MainActivity.TITLE);
    description = planet[0];
    body = planet[1];
    url = planet[2];
    Resources res = getActivity().getResources();
    String mDrawableName = planet[3];
    mDrawableName = mDrawableName.substring(mDrawableName.lastIndexOf("/") + 1,mDrawableName.lastIndexOf("."));
    int resID = res.getIdentifier(mDrawableName , "drawable", getActivity().getPackageName());
    Drawable drawable = res.getDrawable(resID);
    imageView.setImageDrawable(drawable );
    button.setOnClickListener(new View.OnClickListener() {

      public void onClick(View v) {
        Intent i = new Intent(Intent.ACTION_VIEW);
  public PlanetFragment() {
    // Required empty public constructor
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.planet_fragment, container, false);


Java Source Code List