2016-09-06 227 views
1

更新我有一个fragment_1其中有按钮呼叫地址其发送用户fragment_2 填写表格4 5 编辑文本和同fragment_2用户需要按保存表单返回回来填补上fragment_2到这里一切工作fine.In登录我可以看到fragment_1从fragment_2回收站电源适配器没有与更新适配器

Fragm获取数据的细节fragment_1 ent_1其中有RecyclerView显示用户表单填写上Fragment_2

问题是我在不同的method.In获得在fragment_1数据的方法我打电话adapter.notifyDataSetChanged(); 这应该调用适配器方法但只有getItemCount正在运行,而不是其他处理RecyclerView的方法。 请检查logcat的下方,以获取有关问题的理念

这里是我的方法,其中我打电话notifydatasetchanged()

public void PPL_Location(PPL_list_wrapper ppl_list_wrapper){ 
     PPL_wrapper=ppl_list_wrapper; 
     Log.d(TAG,"PROFILE DATA CALLING"); 
     Log.d(TAG,ppl_list_wrapper.toString()); 
     Loc_details.add(PPL_wrapper); 
     Log.d(TAG,PPL_wrapper.getName()); 
     adapter=new ppl_Recycler_Adapter(getActivity(),Loc_details); 
     int item=adapter.getItemCount(); 
    adapter.notifyDataSetChanged(); 
     Log.d(TAG,"Here is the value of Location Details: "+"Size "+Loc_details.size()+" "+"Details "+Loc_details.iterator()+" "+ "Location "+Loc_details.get(0)+" "+item); 
    } 

这里是我的适配器称为PPL_Re_Adapter

public class ppl_Recycler_Adapter extends RecyclerView.Adapter<ppl_Recycler_Adapter.ViewHolder> { 
    List<PPL_list_wrapper> ppl_Details; 
    Context context; 
    public static final String TAG="PPL_Re_Adapter####"; 


    public ppl_Recycler_Adapter(Context context,List<PPL_list_wrapper> ppl_Details) { 
     this.ppl_Details=ppl_Details; 
     this.context=context; 
     Log.d(TAG,"Adapter Constructor Running With Parameters"); 

    } 


    @Override 
    public ppl_Recycler_Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     LayoutInflater layoutInflater= (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View view=layoutInflater.inflate(R.layout.ppl_single_row,parent,false); 
     Log.d(TAG,"onCreate View Holder");  
     return new ViewHolder(view); 
    } 

    @Override 
    public void onBindViewHolder(ppl_Recycler_Adapter.ViewHolder holder, int position) { 
     Log.d(TAG,"onBindViewHolder"); 
     if (ppl_Details.size()==0){ 
      Log.d(TAG,"List is Null");  
     } 
     else { 
      Log.d(TAG,"Process Views Here"); 
     }  
    } 

    @Override 
    public int getItemCount() { 
     if (ppl_Details==null && ppl_Details.isEmpty()){ 
      Log.d(TAG,"List Is Null");  
      return 0;  
     } 
     else { 
      Log.d(TAG,"List Is Not Null"); 
      Log.d(TAG,"Array Size is "+ppl_Details.size()); 
      return ppl_Details.size(); 
     } 
    } 

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 

     ImageView ppl_Image; 
     TextView ppl_name; 
     TextView ppl_address; 
     TextView ppl_timePeriod; 
     ImageButton ppl_delete; 
     ImageButton ppl_Verify; 
     FloatingActionButton fab;  

     public ViewHolder(View itemView) { 
      super(itemView); 
      Log.d(TAG,"View Holder Running"); 
      ppl_Image= (ImageView) itemView.findViewById(R.id.past_permanent_location_picture); 
      ppl_name= (TextView) itemView.findViewById(R.id.name); 
      ppl_address= (TextView) itemView.findViewById(R.id.address); 
      ppl_timePeriod= (TextView) itemView.findViewById(R.id.time_period); 
      ppl_delete= (ImageButton) itemView.findViewById(R.id.delete); 
      ppl_Verify= (ImageButton) itemView.findViewById(R.id.verify); 
      fab= (FloatingActionButton) itemView.findViewById(R.id.PPL_fab_Add_PPL); 
      itemView.setOnClickListener(this);  
     } 

     @Override 
     public void onClick(View v) { 
      Context context=v.getContext(); 
      Intent showPPL_Form=new Intent(context,Add_PPL.class); 
      context.startActivity(showPPL_Form); 
     } 
    } 

这里Logcat。在Logcat中,Log中没有显示来自适配器的logcat然后getItemCount

09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/====Fragment_1====: PROFILE DATA CALLING 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/====Fragment_1====: com.[email protected]426c3f50 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/====Fragment_1====: n sana 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Adapter Constructor Running With Parameters 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: List Is Not Null 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Array Size is 1 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/====Fragment_1====: Here is the value of Location Details: Size 1 Details [email protected] Location com.[email protected]426c3f50 1 
09-06 16:12:46.513 28727-28727/com.example.com.pro_working1 D/Navigation Drawer*****: Here is PPL DATA com.[email protected]426c3f50 
09-06 16:12:46.523 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Adapter Constructor Running With Parameters 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: List Is Not Null 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Array Size is 0 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: List Is Not Null 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Array Size is 0 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: List Is Not Null 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Array Size is 0 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: List Is Not Null 
09-06 16:12:46.533 28727-28727/com.example.com.pro_working1 D/PPL_Re_Adapter####: Array Size is 0 

Fragment_1完整代码

RecyclerView mRecyclerView; 
    RecyclerView.Adapter adapter; 
    List<PPL_list_wrapper> Loc_details=new ArrayList<PPL_list_wrapper>(); 
    FloatingActionButton fab; 
    PPL_list_wrapper PPL_wrapper; 
    public static final String TAG="====Fragment_1===="; 


    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View view=inflater.inflate(R.layout.fragment_fragment_1, container, false); 
     mRecyclerView= (RecyclerView) view.findViewById(R.id.ppl_RecyclerView); 
     mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 
     adapter=new ppl_Recycler_Adapter(getActivity(),Loc_details); 
     mRecyclerView.setAdapter(adapter); 

     fab= (FloatingActionButton) view.findViewById(R.id.PPL_fab_Add_PPL); 

     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       FragmentTransaction fragmentTransaction=getFragmentManager().beginTransaction(); 
       Add_PPL add_ppl=new Add_PPL(); 
       fragmentTransaction.add(R.id.Navigation_Main_Layout,add_ppl); 
       fragmentTransaction.commit(); 
      } 
     }); 




     return view; 

    } 

    public void PPL_Location(PPL_list_wrapper ppl_list_wrapper){ 
     PPL_wrapper=ppl_list_wrapper; 
     Log.d(TAG,"PROFILE DATA CALLING"); 
     Log.d(TAG,ppl_list_wrapper.toString()); 
     Loc_details.add(PPL_wrapper); 
     Log.d(TAG,PPL_wrapper.getName()); 
     adapter=new ppl_Recycler_Adapter(getActivity(),Loc_details); 
     int item=adapter.getItemCount(); 
     adapter.notifyDataSetChanged(); 
     Loc_details.add(PPL_wrapper); 
     Log.d(TAG,"Here is the value of Location Details: "+"Size "+Loc_details.size()+" "+"RecyclerView "+mRecyclerView+" "+ "Location "+Loc_details.get(0)+" "+"Item Size "+item); 
     mRecyclerView.setAdapter(adapter); 
     mRecyclerView.invalidate(); 


    } 
+0

在adapter.notifyDataSetChanged()后再次添加listview.setAdapter(adapter); –

+0

@ user2564055这不会工作。我尝试 – Ritu

回答

0

您首先调用适配器没有结果,那么你填写表格并期望细节填入您RecyclerView和问题是,你得到结果成片段,但你的列表没有那个结果。

现在按照我的代码我试过了,我硬编码适配器的getItemCount返回值为1,它显示所有方法到logcat,所以我只是让你的列表静态,现在它的工作。

请让你列表静态

static List<PPL_list_wrapper> Loc_details=new ArrayList<PPL_list_wrapper>(); 

希望它能帮助

正如你说你的布局同时显示片段一次。其片段的问题,添加或替换,以便按您的代码更改此行

Add_PPL add_ppl=new Add_PPL(); 
fragmentTransaction.add(R.id.Navigation_Main_Layout,add_ppl); 

进入这个

fragmentTransaction.replace(R.id.Navigation_Main_Layout,add_ppl); 

而对于你的第二个问题是出大比分的布局,请检查您的单列布局XML并确保高度为wrap_content或张贴您的代码在这里

+0

Thankyou这么多的工作,但有更多的问题,我面临1)我的fragment_2更改为fragment_1,但它混乱了布局通过显示两个片段在同一时间,直到我按再次添加按钮2)我的1回收站采取全屏和其他人之间后,他们之间的利润率大 – Ritu

+0

检查我更新的答案 – androidXP

+0

谢谢你这么多的帮助,我真的很感激它非常感谢 – Ritu

0

我曾尝试下面的代码和它的工作对我来说:

recyclerView.setAdapter(new RecyclerViewAdapter(newList)); 
recyclerView.invalidate(); 

在你的情况下,它不会发生,因为你是给新数据您以前的活动首先必须填写容器,然后再次发送适配器并使其无效。

+0

当我在我的fragment方法中调用mRecyclerView时,即使在'findviewbyid','setlayoutmanager'后它总是返回null。所以我不能在我的方法中调用recyclerview – Ritu

+0

粘贴整个代码以便理解问题。 @Ritu –

+0

'D/==== Fragment_1 ====:以下是位置详细信息的值:大小2 RecyclerView null位置com.[email protected]4257c1d8项目大小1'执行器后检查详细信息您的代码请参阅RecyclerView的空值 – Ritu

0

你好,你可以尝试做这样的事情,而不是每次创建一个新的适配器尝试清除适配器并添加新的列表。这种方法应该是在你的适配器和mList应该是充满你的适配器列表:

public void setAll(@NonNull 
        final List<Object> yourCustomObjectList) { 
    mList.clear(); 
    mList.addAll(yourCustomObjectList); 
    notifyDataSetChanged(); 
} 
+0

http:// pastebin.com/A7y6Mwik 请检查日志后实施你的代码 – Ritu