Servus stehe mal wieder vor einem nervigen Problem. Ich hab in meiner MainActivity einen FragmentPagerAdapter mit 4 Seiten.
Nun will ich die Buttons die ich auf den verschiedenen Fragments eingebaut hab mit einem onClickListener versehen, wenn man dann drauf klickt soll eine andere Activity geöffnet werden.
hier mal meine MainActivity(entschuldigt den langen Code aber das schliesst evtl Fragen schon mal aus)
package com.example.carmanager;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends FragmentActivity {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
Fragment fragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@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;
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
/* @Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
} */
public Fragment getItem(int position) {
switch (position){
case 0:
fragment = new Section1Activity();
break;
case 1:
fragment = new Section2Activity();
break;
case 2:
fragment = new Section3Activity();
break;
case 3:
fragment = new Section4Activity();
break;
default:
fragment = new Section1Activity();
}
return fragment;
}
@Override
public int getCount() // Seiten des Strip
{
// Show 4 total pages.
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
case 3:
return getString(R.string.title_section4).toUpperCase(l);
}
return null;
}
}
public static class Section1Activity extends Fragment {
public Section1Activity() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section1,
container, false);
return rootView;
}
}
public static class Section2Activity extends Fragment {
public Section2Activity() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section2,
container, false);
return rootView;
}
}
public static class Section3Activity extends Fragment {
public Section3Activity() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section3,
container, false);
return rootView;
}
}
public static class Section4Activity extends Fragment {
public Section4Activity() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section4,
container, false);
return rootView;
}
}
}
Alles anzeigen
hier mal ein screenshot von einer Section(Fragement) auf der man unten den Button sieht
[Blockierte Grafik: http://my.funpic.de/show-photo/801761-PIC.png]
ich weiss eigentlich gar nicht wo ich nun anfangen soll, wo genau muss ich die "R.id.btnFüllungen" in eine Variabel machen? wo muss ich das neue Intent machen? muss ich eine "...java" datei starten und in dieser dann wieder eine "...xml" datei?