更新我有一個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();
}
在adapter.notifyDataSetChanged()後再次添加listview.setAdapter(adapter); –
@ user2564055這不會工作。我嘗試 – Ritu