title: Change activity from button in a fragment
body: <p>Goodmorning everyone, I'm very new on android and I'd like to put an action of a button of a fragment... I'm using this way: </p>
  
  <pre><code>    Button butt1=(Button)findViewById(R.id.btn1);
  
  
  
      butt1.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent int1=new Intent(MainActivity.this,newactivity.class);
              startActivity(int1);
  
  
              finish();
  
  
  
          }
      });
  </code></pre>
  
  <p>The problem is that I don't know where to place this action, if in the main activity class or in the import fragment class, the import fragment class is a list with buttons and I'd like each button to move to another activity.</p>
  
  <p>This is the ImportFragment.class code:</p>
  
  <pre><code>    public class ImportFragment extends Fragment {
  ListView listView;
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_import,container,false);
  
  
  
      return rootView;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the Main Activity code that lead to the fragment by a lateral navigation drawer:</p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity
      implements NavigationView.OnNavigationItemSelectedListener, OnMapReadyCallback {
  private GoogleMap mMap;
  Button enobutt=(Button)findViewById(R.id.enobtn);
  
  SupportMapFragment sMapFragment;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      sMapFragment = SupportMapFragment.newInstance();
      sMapFragment.getMapAsync(this);
  
      setContentView(R.layout.activity_main);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
  
      FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
          }
      });
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
              this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
      drawer.setDrawerListener(toggle);
      toggle.syncState();
  
      NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
      navigationView.setNavigationItemSelectedListener(this);
  
      android.app.FragmentManager fm = getFragmentManager();
      android.support.v4.app.FragmentManager rFm = getSupportFragmentManager();
      if(!sMapFragment.isAdded())
          rFm.beginTransaction().add(R.id.map, sMapFragment).commit();
      else
          rFm.beginTransaction().show(sMapFragment).commit();
  
  
  
  }
  
  @Override
  public void onBackPressed() {
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      if (drawer.isDrawerOpen(GravityCompat.START)) {
          drawer.closeDrawer(GravityCompat.START);
      } else {
          super.onBackPressed();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
  
      android.app.FragmentManager fn = getFragmentManager();
      android.support.v4.app.FragmentManager sFm = getSupportFragmentManager();
      int id = item.getItemId();
  
      if(sMapFragment.isAdded())
           sFm.beginTransaction().hide(sMapFragment).commit();
  
      if (id == R.id.nav_camera) {
          fn.beginTransaction().replace(R.id.content_frame,  new ImportFragment()).commit();
  
      } else if (id == R.id.nav_gallery) {
          if(!sMapFragment.isAdded())
          sFm.beginTransaction().add(R.id.map, sMapFragment).commit();
          else
               sFm.beginTransaction().show(sMapFragment).commit();
  
      } else if (id == R.id.nav_slideshow) {
  
      } else if (id == R.id.nav_manage) {
  
      } else if (id == R.id.nav_share) {
  
      } else if (id == R.id.nav_send) {
  
      }
  
      DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
      drawer.closeDrawer(GravityCompat.START);
      return true;
  }
  
  @Override
  public void onMapReady(GoogleMap googleMap) {
      mMap = googleMap;}
  </code></pre>
  
  <p>}</p>
  
  <p>how can I do?</p>