[Solved] How to parse JSON data into fragments?

you can parse like this: List<RidesData> ridesDatas; /* this is should be parcelable */ private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(FragmentAbout.newInstance(ridesDatas), “ABOUT”); adapter.addFragment(FragmentPointOfInterest.newInstance(ridesDatas),”POI”); viewPager.setAdapter(adapter); } and set constructure to each fragment like this: FragmentAbout.class public static FragmentAbout newInstance(List<RidesData> ridesDatas) { FragmentAbout fragmentAbout = new FragmentAbout(); Bundle arg = new Bundle(); arg.putParcelableArrayList(“data”, … Read more

[Solved] Change Activities’ Fragment Inside the Fragment

Use below method public static void openFragment(FragmentManager manager, Fragment targetFragment) { try { String fragmentName = targetFragment.getClass().getName(); manager.popBackStack(); manager.beginTransaction() .replace(R.id.frameLayout, targetFragment, fragmentName) .addToBackStack(fragmentName) .commit(); } catch (Exception e) { e.printStackTrace(); } } call this method each time when you are opening your fragment. You have to pass two params to this method. targetFragment is the … Read more

[Solved] Application unfortunately stopped on clicking bookmarked item in fragment view Im using json to store title & links

hello guys i used following code & my problem got solved listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Object o = listView.getAdapter().getItem(position); if (o instanceof Map) { final Map map = (Map) o; Intent in = new Intent(getActivity(),HomeFragment.class); in.putExtra(“url”, String.valueOf(map.get(TAG_LINK))); System.out.println(“loading url…”+String.valueOf(map.get(TAG_LINK))+” please wait”); HomeFragment.wv.post(new Runnable() { public … Read more

[Solved] How to replace setContentView in a fragment for SQLdatabase?

First, delete this from your onCreate(): setContentView(R.layout.fragment_section_number1); Next, move the following from your onCreate(): myDb = new DatabaseHelper(this); editName = (EditText) rootview.findViewById(R.id.editText_Name); editSurname = (EditText) rootview.findViewById(R.id.editText_Surname); editBalance = (EditText) rootview.findViewById(R.id.editText_Balance); btnAddData = (Button) rootview.findViewById(R.id.button_add); btnviewAll = (Button) rootview.findViewById(R.id.button_viewAll); AddData(); viewAll(); …to your onCreateView() method: rootview = inflater.inflate(R.layout.fragment_section_number1, container, false); // move it here return rootview; … Read more

[Solved] After changing the package name application giving error ” java.lang.NullPointerException: Attempt to get length of null array” [duplicate]

After changing the package name application giving error ” java.lang.NullPointerException: Attempt to get length of null array” [duplicate] solved After changing the package name application giving error ” java.lang.NullPointerException: Attempt to get length of null array” [duplicate]

[Solved] ListView returning null using Fragment

This is happening because you are using the wrong View variable to find the ListView. ListView lv = (ListView) view.findViewById(R.id.lvAlerts); The view variable here refers to: public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { You need to refer to this view: view = inflater.inflate(R.layout.tab_frag_alerts, container, false); You should change the declaration: View … Read more

[Solved] Register Broadcast receiver in Fragment PageViewer [closed]

No need to register fragment into manifest you can register receiver from fragment like this way private ScreenTimeOutReceiver mScreenTimeOutReceiver; mScreenTimeOutReceiver = new ScreenTimeOutReceiver(); registerReceiver(mScreenTimeOutReceiver, filter); 4 solved Register Broadcast receiver in Fragment PageViewer [closed]

[Solved] Navigating from an activity to a fragment [duplicate]

You can use from switching from Fragment to Activity-: Implement this code on BackPressed-: @Override public void onBackPressed() { super.onBackPressed(); YourFragment mapFragment = new YourFragment(); FragmentManager manager = getFragmentManager(); manager.beginTransaction().replace(R.id.landlord_apartment, mapFragment, mapFragment.getTag()).commit(); } While moving from Fragment to Activity-: startActivity(new Intent(getActivity,YourActivity.Class)); and while moving from activity to Fragment-: YourFragment mapFragment = new YourFragment(); FragmentManager manager … Read more

[Solved] Choosing language at startup

If I understand you correctly you wish to display that activity only when the user runs the app for the first time. Well, here’s what you can do: 1) Get a handle to a SharedPreference. This is to store if the user has already selected the language or not. SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); 2) Create … Read more

[Solved] How to create layout like in this image? [closed]

Not sure is this what you want. You may try. <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”horizontal” android:gravity=”start” android:background=”@android:color/white” android:padding=”12dp”> <ImageView android:id=”@+id/image” android:layout_width=”80dp” android:layout_height=”70dp” android:layout_centerVertical=”true” android:layout_gravity=”left”/> <RelativeLayout android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_toRightOf=”@+id/image” android:layout_centerVertical=”true” android:paddingLeft=”6dp” android:orientation=”vertical” android:layout_alignParentRight=”true” android:layout_alignParentEnd=”true”> <LinearLayout android:id=”@+id/ll1″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”horizontal”> <TextView android:id=”@+id/name” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:textSize=”18sp” android:text=”Depeche Mode” android:singleLine=”true” /> </LinearLayout> <LinearLayout android:id=”@+id/ll2″ android:layout_below=”@+id/ll1″ android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”horizontal”> <TextView … Read more

[Solved] how to replace some character’s of String

You can use string replace method. see below String number = +9231235410; String newNumber = number.replace(“+92″,”0”); EDIT: this one is base on your code private String modifyNumber(String num) { if (num.startsWith(“+92”)) { num = num.replaceFirst(“\\+(92)”, “0”);} return num;} Note: In java, you need to have double backslash since the \ is a unique java character. … Read more

[Solved] When should I use layout_centerHorizontal=true and gravity=”center_horizonatal” and foregroundGravity=”centerHorizontal”?

When you use RelativeLayout – You should use layout_centerHorizontal,layout_centerVertical,layout_centerInParent but when you use LinearLayout , you should use gravity to align children i.e., layout_gravity and gravity. foregroundGravity is used with foreground tag. What is in foreground it will align according to foregroundGravity solved When should I use layout_centerHorizontal=true and gravity=”center_horizonatal” and foregroundGravity=”centerHorizontal”?

[Solved] OnClick button replacing fragment many times with FragmentTransaction, ignoring Tag

This line of code is misplaced: Fragment fragment = fm.findFragmentByTag(MAIN); You have it outside of the onClick() method, which means that the value of fragment is determined once (when you create/assign the OnClickListener) and then reused every time the button is clicked. Just move that line inside the onClick() method: @Override public void onClick(View view) … Read more

[Solved] calling an activity from fragment activity through Intent [closed]

the Intent constructor accepts two arguments. first argument is your Context and the second one is your Activity class. in your fragment, you can access your Context via getActivity method. here is what you should do : Intent i = new Intent(getActivity(), MyActivity.class); 0 solved calling an activity from fragment activity through Intent [closed]