logo
down
shadow

How to start another Activity using Button inside the Fragment


How to start another Activity using Button inside the Fragment

By : user2956294
Date : November 22 2020, 10:54 AM
This might help you Try replacing getActivity().startActivity() method, with startActivity() and it would work!.
Below is the complete code :
code :
public FindPeopleFragment(){} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_find_people, container, false);

    Button button = (Button)view.findViewById(R.id.button1);
    button.setOnClickListener(new OnClickListener()
    { 
        @Override 
        public void onClick(View v){
            switch(v.getId()){

            case R.id.button1:
                Intent intent1 = new Intent(getActivity(), ResearchStudy.class);
                startActivity(intent1);//Edited here
                break; 


            } 
        } 
    }); 

    return view;
} 


Share : facebook icon twitter icon
Button to start new Activity (Fragment?) from ListView

Button to start new Activity (Fragment?) from ListView


By : Frank DeCaire
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Add button to list_item then set onclick listener to the button inside the adapter
code :
<Button  android:id="@+id/button1"/>
     holder.go= (Button) convertView.findViewById(R.id.button1);


     holder.go.setOnClickListener(new OnClickListener() {   

        @Override
        public void onClick(View v) {
            //start next activity here

        }
    });
How to start an activity with a button from a fragment?

How to start an activity with a button from a fragment?


By : user3218033
Date : March 29 2020, 07:55 AM
This might help you Getting a reference to a View in the onCreate() method of a Fragment will not work, because the Fragment's layout has not yet been inflated.
All you need to do is replace
code :
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Button subTip = (Button) getActivity().findViewById(R.id.subTip);
    subTip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent (v.getContext(),SUBMIT_TIP.class);
            startActivityForResult(intent,0);
        }
    });
}
@Override
public void onViewCreated (View view, Bundle savedInstanceState){

    final FloatingActionButton subTip = (FloatingActionButton) view.findViewById(R.id.subTip);
    subTip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent (v.getContext(),SUBMIT_TIP.class);
            startActivityForResult(intent,0);
        }
    });
}
Is it possible to start a fragment a new fragment activity after a button is pressed?

Is it possible to start a fragment a new fragment activity after a button is pressed?


By : Les Hollett
Date : March 29 2020, 07:55 AM
Hope that helps FragmentActivity is a sub class of activity so it also has the startActivity() method
Suppose we want to start ActivityB from a Fragment
code :
Intent intent = new Intent(getActivity(), ActivityB.class);
startActivity(intent);
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
make image button for start activity in fragment?

make image button for start activity in fragment?


By : Mahfuzur Rahman
Date : March 29 2020, 07:55 AM
This might help you this is my fragment , Use Intent to start Activity.
code :
 public class TabFragment1 extends Fragment {
    ImageButton imageButton;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                                Bundle savedInstanceState) {

        View view =  inflater.inflate(R.layout.fragment_tab_fragment1, container, false);
        imageButton = (ImageButton)view.findViewById(R.id.imageButton);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), NewActivity.class));
            }
        });
        return view;
      }
      }
    <?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="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text=" تخیلی "
        android:id="@+id/textview"
        android:layout_gravity="right"
        android:textSize="35sp"
        android:layout_marginRight="15dp"/>

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"/>

</LinearLayout>
I have a checkbox inside a fragment and i want to it respond on click of a button this button is inside my main activity

I have a checkbox inside a fragment and i want to it respond on click of a button this button is inside my main activity


By : shhaugen
Date : March 29 2020, 07:55 AM
should help you out You can use interface to communicate back to MainActivity.
Create a interface and implement it on MainActivity. Pass the implemented interface to fragment and store it in the fragment Then When your checkbox state change check that the stored interface is null or not if not null then call the implemented method of the interface, which is actually implemented in MainActivity. This way you can communicate back to MainActivity. In MainActivity store your checkbox state and do what you want to do in button press.
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org