1

I am creating list view which contain text view,image and google map.

Code for list view layout:-

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >


    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:orientation="horizontal"
          android:background="#ffffff"
        android:paddingLeft="3dp"
        android:paddingRight="3dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="3dp"
            android:layout_marginTop="3dp"
            android:scaleType="fitXY"
            android:src="@drawable/profile_pic_bg" />

    <TextView
        android:id="@+id/textView_username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView_time"
        android:layout_alignRight="@+id/textView_time"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#0A7692"
        android:textSize="15dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView_time"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView_username"
        android:layout_toRightOf="@+id/imageView1"
        android:gravity="left|center"
         android:layout_marginLeft="15dp"
        android:layout_marginTop="4dp"
        android:textColor="#BBB9BC"
            android:text=""
        android:textSize="13dp"
         android:textStyle="bold" 
        android:textAppearance="?android:attr/textAppearanceLarge"
       />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="3dp"
          android:background="#ffffff"
        android:paddingRight="3dp" >

        <TextView
            android:id="@+id/customtxtmessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:ellipsize="end"
            android:maxLines="5"
            android:autoLink="web"
            android:linksClickable="true"
            android:text=""
            android:textColor="#000000" />


        <cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager
            android:id="@+id/view_pager"
            android:layout_marginLeft="10dp"
            android:layout_width="fill_parent"
            android:layout_height="150dp"
            android:layout_marginTop="5dp"
            android:background="#ffffff"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:visibility="visible" >
        </cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager>
    </LinearLayout>

       <LinearLayout
        android:id="@+id/customwall_lin_setwatchlist"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="#eef7fa"
        android:gravity="center_vertical" >


        <TextView
            android:id="@+id/customtxtlike"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#D56438" />

        <ImageView
            android:id="@+id/customimgdot"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:src="@drawable/dot_sep" />

        <TextView
            android:id="@+id/customtxtcomment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="Comment"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#D56438" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|right" >



            <TextView
                android:id="@+id/customtxttotallikes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="15dp"
                android:drawableLeft="@drawable/heart_icon"
                android:gravity="center"     
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D56438" />

            <TextView
                android:id="@+id/customtxttotalcomments"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:drawableLeft="@drawable/comment_icon"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#D56438" />
        </LinearLayout>
    </LinearLayout>

         <LinearLayout
        android:id="@+id/customlayoutgray"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#a3a8aa"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView_temp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#a3a8aa"
            android:textSize="6sp" />
    </LinearLayout>

</LinearLayout>



    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>

Code for List view adapter is:-

/********* Adapter class extends with BaseAdapter and implements with OnClickListener ************/
public class CustomAdapter extends BaseAdapter   {

         /*********** Declare Used Variables *********/
         private FragmentActivity activity;
         private ArrayList data;
         public ArrayList CommentData;
         private static LayoutInflater inflater=null;
         public Resources res;
         CommonWallBean tempValues=null;
         ViewHolder holder;
         int i=0;
         public static  String id="";
         String TextOfLike="";
         SupportMapFragment mapFragment;
         GoogleMap map;

         HashMap<String, String> mMarkerPlaceLink = new HashMap<String, String>();

         Context con;

         /*************  CustomAdapter Constructor *****************/
         public CustomAdapter(Context c,FragmentActivity a, ArrayList d,ArrayList CommentData,Resources resLocal) {

                /********** Take passed values **********/
                 activity = a;
                 data=d;
                 res = resLocal;
                 con=c;
                 CommentData=CommentData;

                 /***********  Layout inflator to call external xml layout () ***********/
                  inflater = ( LayoutInflater )activity.
                                              getSystemService(Context.LAYOUT_INFLATER_SERVICE);

         }

         /******** What is the size of Passed Arraylist Size ************/
         public int getCount() {

             if(data.size()<=0)
                 return 1;
             return data.size();
         }

         public Object getItem(int position) {
             return position;
         }

         public long getItemId(int position) {
             return position;
         }

         /********* Create a holder Class to contain inflated xml file elements *********/
         public static class ViewHolder{

             public TextView customtxtmessage, customtxttime,customtxttotallikes,textView_time,textView_username
                            ,text_likes;
             public ViewPager view_pager;
             public ImageView user_image,customimguseravtar;
             public TextView textViewLike,customtxtcomment,customtxttotalcomments;

             public MapView mapView;


         }

         /****** Depends upon data size called for each row , Create each ListView row *****/
         public View getView(int position, View convertView, ViewGroup parent) {

             View vi = convertView;

             final PagerAdapter adapter;

             if(convertView==null){

                 /****** Inflate tabitem.xml file for each row ( Defined below ) *******/
                 vi = inflater.inflate(R.layout.wall, null);

                 /****** View Holder Object to contain tabitem.xml file elements ******/

                 holder = new ViewHolder();
               //  holder.customtxttime = (TextView) vi.findViewById(R.id.customtxttime);
                 holder.textView_username=(TextView)vi.findViewById(R.id.textView_username);
                 holder.customimguseravtar=(ImageView)vi.findViewById(R.id.imageView1);
                 holder.textView_time=(TextView)vi.findViewById(R.id.textView_time);
                 holder.view_pager=(ViewPager)vi.findViewById(R.id.view_pager);
                 holder.textViewLike=(TextView)vi.findViewById(R.id.customtxtlike);
                 holder.customtxtmessage=(TextView)vi.findViewById(R.id.customtxtmessage);
                 holder.customtxttotallikes=(TextView)vi.findViewById(R.id.customtxttotallikes);
                 holder.customtxtcomment=(TextView)vi.findViewById(R.id.customtxtcomment);
                 holder.customtxttotalcomments=(TextView)vi.findViewById(R.id.customtxttotalcomments);

                 mapFragment = (SupportMapFragment) activity.getSupportFragmentManager().findFragmentById(R.id.map);
                 // Getting GoogleMap object from the fragment
                 map = mapFragment.getMap();


                 // Getting reference to the SupportMapFragment
                // SupportMapFragment fragment = ( SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);




                 /************  Set holder with LayoutInflater ************/
                 vi.setTag( holder );
             }
             else{
                 holder=(ViewHolder)vi.getTag();
             }
              if(position<data.size()){

                 /***** Get each Model object from Arraylist ********/
//                 tempValues=null;
                 tempValues = ( CommonWallBean ) data.get( position );


                 /************  Set Model values in Holder elements ***********/

                  holder.textView_time.setText( tempValues.getDate());
                  holder.textView_username.setText( tempValues.getEmployeeName());
                  holder.textViewLike.setText(tempValues.getValueOfLike());
                  holder.customtxtmessage.setText(Html.fromHtml(tempValues.getPostMessage()));
                  holder.customtxttotallikes.setText(tempValues.getPostLikeCount());
                  holder.customtxttotalcomments.setText(tempValues.getPostCommentCount());  

                  try {
                    String url = Const.NewbaseurlPhoto + tempValues.getPhotographFileName();
                    System.out.println("Thumbnil Url "+url);
                    Picasso.with(activity).load(url).into(holder.customimguseravtar);

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                String wallPhotos = tempValues.getWallPhotograph();
                String latitude = tempValues.getLatitude();
                String longitude = tempValues.getLongitude();


                 if (latitude != null && !latitude.isEmpty() && !latitude.equals("null")){


                    holder.view_pager.setVisibility(View.GONE);

                    String Latitude = tempValues.getLatitude();
                    String Longitude = tempValues.getLongitude();

                    //map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
                    // Showing / hiding your current location
                    map.setMyLocationEnabled(false);
                    // Enable / Disable zooming controls
                    map.getUiSettings().setZoomControlsEnabled(false);
                    // Enable / Disable my location button
                    map.getUiSettings().setMyLocationButtonEnabled(false);
                    // Enable / Disable Compass icon
                    map.getUiSettings().setCompassEnabled(false);
                    // Enable / Disable Rotate gesture
                    map.getUiSettings().setRotateGesturesEnabled(false);
                    // Enable / Disable zooming functionality
                    map.getUiSettings().setZoomGesturesEnabled(false);

                    MapsInitializer.initialize(con);
                    // Updates the location and zoom of the MapView
                    double lat = Double.valueOf("23.012034");
                    double longi = Double.valueOf("72.510754");
                    MarkerOptions marker = new MarkerOptions().position(
                            new LatLng(lat, longi))
                            .title("Hello Maps");
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_RED));
                    map.addMarker(marker);

                    //Zoom Particular position
                    CameraPosition cameraPosition = new CameraPosition.Builder()
                            .target(new LatLng(lat,
                                    longi)).zoom(12).build();

                    map.animateCamera(CameraUpdateFactory
                            .newCameraPosition(cameraPosition));



                }else {
                    holder.view_pager.setVisibility(View.GONE);

                }

     }


             return vi;
         }

    }
  } 
}

The Log Cat is :

FATAL EXCEPTION: main
 Process: com.vervesys.konnect, PID: 26705
 android.view.InflateException: Binary XML file line #178: Error inflating class fragment
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
     at com.vervesys.konnect.adapter.CustomAdapter.getView(CustomAdapter.java:130)
     at android.widget.AbsListView.obtainView(AbsListView.java:2255)
     at android.widget.ListView.makeAndAddView(ListView.java:1790)
     at android.widget.ListView.fillDown(ListView.java:691)
     at android.widget.ListView.fillFromTop(ListView.java:752)
     at android.widget.ListView.layoutChildren(ListView.java:1630)
     at android.widget.AbsListView.onLayout(AbsListView.java:2087)
     at android.view.View.layout(View.java:14860)
     at android.view.ViewGroup.layout(ViewGroup.java:4643)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
     at android.view.View.layout(View.java:14860)
     at android.view.ViewGroup.layout(ViewGroup.java:4643)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
     at android.view.View.layout(View.java:14860)
     at android.view.ViewGroup.layout(ViewGroup.java:4643)
     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
     at android.view.View.layout(View.java:14860)
     at android.view.ViewGroup.layout(ViewGroup.java:4643)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
     at android.view.View.layout(View.java:14860)
     at android.view.ViewGroup.layout(ViewGroup.java:4643)
     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
     at android.view.View.layout(View.java:14860)
     at android.view.ViewGroup.layout(ViewGroup.java:4643)
     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2013)
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1770)
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
     at android.view.Choreographer.doFrame(Choreographer.java:544)
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
     at android.os.Handler.handleCallback(Handler.java:733)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:136)
     at android.app.ActivityThread.main(ActivityThread.java:5086)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:515)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
     at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.IllegalArgumentException: Binary XML file line #178: Duplicate id 0x7f0d00c0, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2293)
     at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
     at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
    at android.support.v4.app.BaseFragmentActivityHoneycomb.o
03-18 16:56:08.410 26705-27435/com.vervesys.konnect D/dalvikvm: GC_FOR_ALLOC freed 3139K, 28% free 8554K/11772K, paused 46ms, total 46ms

Please help me to solve this issue, i am not able to figure out what is wrong with this code.

Please help for the same.

Amee Joshi
  • 115
  • 7
  • Remove `xmlns:android="http://schemas.android.com/apk/res/android"` from line 178 of your xml – antonio Mar 18 '16 at 10:58
  • in your layout file ; the map fragment; instead of class:"com.google.android.gms.maps.SupportMapFragment" use this **android:name="com.google.android.gms.maps.SupportMapFragment"** – DJphy Mar 18 '16 at 11:03
  • Tried both your suggestion @antonio and Djphy but it's not working – Amee Joshi Mar 18 '16 at 11:07

3 Answers3

1

Just remove xmlns:android="http://schemas.android.com/apk/res/android"

in this line

<fragment xmlns:android="http://schemas.android.com/apk/res/android"

AND

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

You need have at the end :

<fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />
Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
0

After struggle a lot for this issue, finally i found that google provides static map in URL.

By using Mapview or fragmentManager will be heavy and app will be slow. so for this better option is to use google static map api.

More details are provided in Android - MapView contained within a Listview and

https://developers.google.com/maps/documentation/staticmaps/

I posted this answer as it may help other.

Community
  • 1
  • 1
Amee Joshi
  • 115
  • 7
0

you can try this line of code in your adapter class for inflating layout

vi = inflater.inflate(R.layout.wall, parent,false);

Rahul Chaudhary
  • 1,059
  • 1
  • 6
  • 15