java.lang.IllegalArgumentException:重复ID为0x7f0d00c0,标记为null,另有一个com.google.android.gms.maps.SupportMapFragment片段

时间:2016-03-18 10:56:06

标签: java android google-maps listview

我正在创建包含文本视图,图片和Google地图的列表视图。

列表视图布局代码: -

  <?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>

列表视图适配器的代码是: -

/********* 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;
         }

    }
  } 
}

Log Cat是:

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

请帮我解决这个问题,我无法弄清楚这段代码有什么问题。

请帮忙。

3 个答案:

答案 0 :(得分:1)

只需删除fabric.Image.filters.Redify = fabric.util.createClass({ type: 'Redify', applyTo: function(canvasEl) { var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), data = imageData.data; for (var i = 0, len = data.length; i < len; i += 4) { data[i + 1] = 0; data[i + 2] = 0; } context.putImageData(imageData, 0, 0); } }); fabric.Image.filters.Redify.fromObject = function(object) { return new fabric.Image.filters.Redify(object); };

即可

在这一行

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

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

你最后需要:

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

答案 1 :(得分:0)

经过这个问题的斗争很多,最后我发现谷歌提供了URL中的静态地图。

使用Mapview或fragmentManager会很重,应用程序会很慢。所以对于这个更好的选择是使用谷歌静态地图API。

Android - MapView contained within a Listview

中提供了更多详细信息

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

我发布了这个答案,因为它可能有助于其他人。

答案 2 :(得分:0)

您可以在适配器类中尝试这行代码来扩充布局

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