public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
logger = LogWrapper.getInstance();
logger.debugLog(TAG+"onCreateView", "On create View Start");
parentActivity = (CoreWorkFlowActivity) getActivity();
mView = inflater.inflate(R.layout.summary_layout, container, false);
this.inflater = inflater;
activateSystem = (Button)mView.findViewById(R.id.activate_system);
ivretestAll = (Button)mView.findViewById(R.id.ivretest);
activateSystem.setOnClickListener(this);
ivretestAll.setOnClickListener(this);
explistView = (ExpandableListView)mView.findViewById(R.id.explistview);
explistView.setGroupIndicator(null);
hiddenlayout = (RelativeLayout)mView.findViewById(R.id.hiddenLayout);
buttonlayout = (RelativeLayout)mView.findViewById(R.id.buttonlayout);
prepareListData();
explistAdapter = new CustomExpandableListAdapter(parentActivity, listDataHeader, listDataChild);
// setting list adapter
explistView.setAdapter(explistAdapter);
explistAdapter.notifyDataSetChanged();
return mView;}
when i am navigating through a viewpager the fragment's UI is not refreshed .Please give me a solution
Related
Hello ladies and gentlmen,
Though I can receive data (reservations) on my screen, however I can not display some textviews on the screen.
public class Res extends Fragment {
ListView lview;
ListAdapter adapter;
ProgressDialog loading;
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.reslist, container, false);
lview = view.findViewById(R.id.lview);
getReservations();
return view;
here If I inflate fragment_reservation instead of reslist , I can display textviews,but I can display listview.
and here my listadapter code;
adapter = new SimpleAdapter(getActivity(),list,R.layout.fragment_reservations,
new String[]{"name", "email", "phone", "arriving", "departure", "pax", "roomtype", "rate"}, new int[]{R.id.textView, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6, R.id.textView7, R.id.textView8});
lview.setAdapter(adapter);
loading.dismiss();
maybe problem about getActivty() and I need to use different method calling..
Thanks in advance...
here the photo of the screen
SCREEEN
I think problem is with parameter "list"(ArrayList) while creating SimpleAdapter object. Here is my code to do the same thing, it is working fine.
public class BlankFrag extends Fragment {
private View v;
private ListView listView;
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState){
v = inflater.inflate(R.layout.blank_fragment, container, false);
listView = v.findViewById(R.id.dummy_list);
ArrayList<HashMap<String, String>> list = new ArrayList<>();
//populating dummy content
for(int i=0; i<5; i++){
HashMap<String, String> temp = new HashMap<>();
temp.put("name", "name"+Integer.toString(i));
temp.put("sname", "sname"+Integer.toString(i));
list.add(temp);
}
SimpleAdapter adapter = new SimpleAdapter(getActivity(), list, R.layout.single_item, new String[]{"name", "sname"}, new int[]{R.id.name, R.id.sname});
listView.setAdapter(adapter);
return v;
}
}
it says IllegalArgumentException: No view found for id for fragment when I'm trying to setview.I know problem lies at 3rd and 4th line. it's News.java file news is a fragment.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setContentView(R.layout.fragment_news);
listView = (ListView) getActivity().findViewById(R.id.list);
feedItems = new ArrayList<FeedItem>();
listAdapter = new FeedListAdapter(this, feedItems);
listView.setAdapter(listAdapter);
Fragment.java file is look like below code :
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_news, container, false);
//ButterKnife.bind(this, view);
init(view);
return view;
}
after that in init method type below code:
private void init(View view){
listView = (ListView) view.findViewById(R.id.list);
feedItems = new ArrayList<FeedItem>();
listAdapter = new FeedListAdapter(this, feedItems);
listView.setAdapter(listAdapter);
}
also u don't forgot to extends Fragment
i have a created a fragment in which i want to display listview but my fragment is dislplayed wtihout the listview nor i am getting an error
i have read many solutions to this question but i can't find the right one.
a small help would be great.thank you!
public class ServicesFragment extends Fragment {
public TextView servicesName;
ListView listView;
String[] servicesNameArray;
int[] serviceImages = {
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera,
R.drawable.ic_menu_camera
};
public ServicesFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.services_fragment, container, false);
listView = (ListView) view.findViewById(R.id.listView_services);
ServicesAdapter adapter = new ServicesAdapter(getContext(), servicesNameArray, serviceImages);
listView.setAdapter(adapter);
Resources resources = getResources();
resources.getStringArray(R.array.servicesName);
return view;
}
public class ServicesAdapter extends ArrayAdapter<String> {
Context c;
int[] servicesImageArray;
String[] servicesNameArray;
public ServicesAdapter(Context context, String[] servicesNameArray, int[] serviceImages) {
super(context, R.layout.services_layout, R.id.listView_services);
this.c = context;
this.servicesImageArray = serviceImages;
this.servicesNameArray = servicesNameArray;
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.services_layout, parent, false);
ImageView serviceImages = (ImageView) view.findViewById(R.id.image_of_services);
TextView servicesName = (TextView) view.findViewById(R.id.name_of_services);
serviceImages.setImageResource(servicesImageArray[position]);
servicesName.setText(servicesNameArray[position]);
return view;}}}
You are not assigning value to the string array: use
servicesNameArray = getResources().getStringArray(R.array.servicesName);
and instead of :
ServicesAdapter adapter = new ServicesAdapter(getContext(), servicesNameArray, serviceImages);
use the activity context:
ServicesAdapter adapter = new ServicesAdapter(this.getActivity(), servicesNameArray, serviceImages);
you need to notify you adapter about your data set size:
super(context, R.layout.services_layout, servicesNameArray); //change here
I think this issue cause you dont pass data in correct way
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.services_fragment, container, false);
Resources resources = getResources();
servicesNameArray = resources.getStringArray(R.array.servicesName);
listView = (ListView) view.findViewById(R.id.listView_services);
ServicesAdapter adapter = new ServicesAdapter(getContext(), servicesNameArray, serviceImages);
listView.setAdapter(adapter);
return view;
}
I'm trying to access from my code to listview and a textview, I read a lot of posts on the internet but I didn't find anything that works for me.
I have a blank fragment like this:
public class MyFrag extends Fragment {
//My Code
List<String> Names = new ArrayList<String>();
List<Double> Prices = new ArrayList<Double>();
List<String> Dates = new ArrayList<String>();
List<String> Hours = new ArrayList<String>();
List<String> iDs = new ArrayList<String>();
Double TotalMy = 0.00;
SimpleAdapter adapter;
public MyFrag() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
//RelativeLayout rootView = (RelativeLayout) inflater.inflate(R.layout.fragment_my_frag, container, false);
//View view = inflater.inflate(R.layout.fragment_my_frag, container, false);
LayoutInflater lf = getActivity().getLayoutInflater();
View view = lf.inflate(R.layout.fragment_my_frag, container, false);
ListView listview = (ListView) getView().findViewById(R.id.list);
TextView textTotalMy = (TextView) getView().findViewById(R.id.textTotalMy1);
return view;
}
But when I open the fragment the application crashes.
Please help me
I solved it by creating the same Relative Layout programmatically
View fragment_view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
List<String> datalist2 = new ArrayList<>();
datalist2.add("FirstAid");
datalist2.add("Login");
datalist2.add("Profile");
datalist2.add("Ambulance");
datalist2.add("Medicine");
datalist2.add("News");
datalist2.add("HRM");
fragment_view = inflater.inflate(R.layout.fragment_menu_bar, container, false);
list_view_menu_adapter adapter2=new list_view_menu_adapter (getContext(),datalist2);
final ListView L2= (ListView) fragment_view.findViewById(R.id.menu_scroll_list);
L2.setAdapter(adapter2);
How can I change this list to horizontal currently it is showing me verticaly without RecyclerView if possible