title: Converting Intent to Fragment in Android
body: <p>In general most of the time I work with Intent rather than Fragment because I found It somehow complex. I have a class with ListView to show some data from an array and I want to convert it in Fragment also want to pass the extras in a new fragmented class.</p>
  
  <p>ListView Class:</p>
  
  <pre><code>public class MainActivity extends Activity {
      ListView list;
      String[] web = { "Google", "Twitter", "Windows", "Bing", "Itunes",
              "Wordpress", "Drupal" };
      Integer[] imageId = { R.drawable.ic_launcher, R.drawable.ic_launcher,
              R.drawable.ic_launcher, R.drawable.ic_launcher,
              R.drawable.ic_launcher, R.drawable.ic_launcher,
              R.drawable.ic_launcher
  
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          CustomList adapter = new CustomList(MainActivity.this, web, imageId);
          list = (ListView) findViewById(R.id.list);
          list.setAdapter(adapter);
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
                  Toast.makeText(MainActivity.this,
                          "You Clicked at " + web[+position], Toast.LENGTH_SHORT)
                          .show();
  
  
                  Intent i = new Intent(MainActivity.this, intent.class);
                  i.putExtra("name", web[+position]);
                  startActivity(i);
  
              }
          });
  
      }
  
  }
  </code></pre>
  
  <p>CustomList Class:</p>
  
  <pre><code>public class CustomList extends ArrayAdapter&lt;String&gt; {
  
      private final Activity context;
      private final String[] web;
      private final Integer[] imageId;
  
      public CustomList(Activity context, String[] web, Integer[] imageId) {
          super(context, R.layout.list_single, web);
          this.context = context;
          this.web = web;
          this.imageId = imageId;
  
      }
  
      @Override
      public View getView(int position, View view, ViewGroup parent) {
          LayoutInflater inflater = context.getLayoutInflater();
          View rowView = inflater.inflate(R.layout.list_single, null, true);
          TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
  
          ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
          txtTitle.setText(web[position]);
  
          imageView.setImageResource(imageId[position]);
          return rowView;
      }
  }
  </code></pre>
  
  <p>I got a main class with three tabs created using fragment and in this class I would like to add the ListView!</p>
  
  <pre><code>public class LayoutOne extends Fragment {
  
  
      public static Fragment newInstance(Context context) {
          LayoutOne f = new LayoutOne();  
  
          return f;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
          ViewGroup root = (ViewGroup) inflater.inflate(R.layout.layout_one, null);
          return root;
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
  
      }
  
  }
  </code></pre>
  
  <p>What I want to do is to show the listview in the fragment class and when a list item will be click I want to launch the New Intent to show which Item was clicked!</p>