title: How to make a listview fragment with image?
body: <p>I tried to put this code in other project but it doesn't work.</p>
  
  <p><strong><em>ListView Activity Project</em></strong></p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ListView fst;
      String[] placesname={"Place 1","Place 2","Place 3","Place 4","Place 5","Place 6"};
      String[] desc={"Desc 1","Desc 2","Desc 3","Desc 4","Desc 5","Desc 6"};
      Integer[] imgid={R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5,R.drawable.img6};
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          fst= (ListView) findViewById(R.id.listview);
          CustomListview customListview=new CustomListview(this,placesname,desc,imgid);
          fst.setAdapter(customListview);
          fst.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
                  if(position==0) {
                      Intent myintent = new Intent(view.getContext(),touristspot1.class);
                      startActivityForResult(myintent,0);
                  }
                  if(position==1) {
                      Intent myintent = new Intent(view.getContext(),touristspot2.class);
                      startActivityForResult(myintent,1);
                  }
              }
          });
  
      }
  }
  </code></pre>
  
  <p><strong>CustomListview</strong></p>
  
  <pre><code>public class CustomListview extends ArrayAdapter&lt;String&gt; {
  
      private String[] placesname;
      private String[] desc;
      private Integer[] imgid;
      private Activity context;
      public CustomListview(Activity context, String[] placesname, String[] desc, Integer[] imgid) {
          super(context, R.layout.listview_layout, placesname);
  
          this.context = context;
          this.placesname = placesname;
          this.desc = desc;
          this.imgid = imgid;
      }
  
      @NonNull
      @Override
      public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
          View r=convertView;
              ViewHolder viewHolder=null;
              if (r==null)
              {
  
                  LayoutInflater layoutInflater=context.getLayoutInflater();
                  r=layoutInflater.inflate(R.layout.listview_layout,null,true);
                  viewHolder=new ViewHolder(r);
                  r.setTag(viewHolder);
              }
              else {
  
                  viewHolder= (ViewHolder) r.getTag();
              }
  
              viewHolder.ivw.setImageResource(imgid[position]);
              viewHolder.tb1.setText(placesname[position]);
              viewHolder.tb2.setText(desc[position]);
              return r;
  
      }
      class ViewHolder
      {
          TextView tb1;
          TextView tb2;
          ImageView ivw;
          ViewHolder(View v)
          {
              tb1=v.findViewById(R.id.tubbaname);
              tb2=v.findViewById(R.id.tubbadesciption);
              ivw=v.findViewById(R.id.imageView);
          }
      }
  }
  </code></pre>
  
  <p><strong><em>The codes I wrote above doesn't work when I put to the fragment. The codes I wrote below is another project where I put the codes mentioned above</em></strong></p>
  
  <p><strong>Listview Fragment</strong></p>
  
  <p><strong>PPTP</strong></p>
  
  <pre><code>public class pptp extends Fragment {
  
  
      public pptp() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.activity_pptp, container, false);
          // Inflate the layout for this fragment
          String[] awayStrings = {
                  "Top Wonders",
                  "Top Tourist Destinations",
                  "Cities to Visit",
                  "Romantic Places",
                  "Family Destinations",
                  "Best Honeymoon Destinations",
                  "Adventure Sports Destinations",
                  "Amusement Parks",
                  "Best Beaches",
                  "Monuments",
                  "Historical Places",
                  "National Parks and wild life sanctuary",
                  "Places to Visit",
                  "Beautiful Caves",
                  "Best Cathedrals",
                  "EcoNature Tourism",
                  "Top Museums",
                  "Beautiful Lakes",
                  "Most Beautiful Sandbars",
                  "Popular Street foods",
                  "General Information",
          };
  
          ListView lv = (ListView) view.findViewById(R.id.listView);
  
          ArrayAdapter&lt;String&gt; lva = new ArrayAdapter&lt;String&gt;(
                  getActivity(), android.R.layout.simple_list_item_1, awayStrings);
          lv.setAdapter(lva);
  
          lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
  
                  if(position == 0){
                      List1TW fragment = new List1TW();
                      FragmentTransaction transaction = getFragmentManager().beginTransaction();
                      transaction.replace(R.id.fragment_container, fragment);
                      transaction.addToBackStack(null);
                      transaction.commit();
  
                  }
              }
          });
          return view;
      }
  
  }
  </code></pre>
  
  <p><strong>ViewPageAdapter</strong></p>
  
  <pre><code>public class ViewPageAdapter extends FragmentPagerAdapter{
  
      ArrayList&lt;Fragment&gt; fragments = new ArrayList&lt;&gt;();
      ArrayList&lt;String&gt; tabTitles = new ArrayList&lt;&gt;();
  
      public void addFragments (Fragment fragments,String tabTitles){
          this.fragments.add(fragments);
          this.tabTitles.add(tabTitles);
      }
  
      public ViewPageAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          return fragments.get(position);
      }
  
      @Override
      public int getCount() {
          return fragments.size();
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return tabTitles.get(position);
      }
  }
  </code></pre>
  
  <p><strong><em>In Fragment what will I do to view image in listview?</em></strong></p>