I'm getting this error at the moment:
"type missmatch cannot convert from FragmentA to fragment".
Under each If statement
if(arg0==0)
{
fragment=new FragmentA();
}
if(arg0==0)
{
fragment=new FragmentB();
}
if(arg0==0)
{
fragment=new FragmentC();
}
So I'm wondering if it's something to do with my import files? As I keep having trouble with those. I'll list the Import files and then the relevant code. Could be either the method or the imports not to sure which.
Ok so here is the full code:
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBar.TabListener;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class Main_activity extends ActionBarActivity implements TabListener {
public static final String PREFS_NAME = "MyPreferncesfile";
ViewPager viewPager;
ActionBar actionBar;
@Override
public void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
viewPager=(ViewPager) findViewById(R.id.pager);
actionBar=getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1=actionBar.newTab();
tab1.setText("Tab 1");
tab1.setTabListener(this);
ActionBar.Tab tab2=actionBar.newTab();
tab2.setText("Tab 2");
tab2.setTabListener(this);
ActionBar.Tab tab3=actionBar.newTab();
tab3.setText("Tab 3");
tab3.setTabListener(this);
actionBar.addTab(tab1);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
}
public void onTabReselected1(Tab tab, FragmentTransaction ft) {
Log.d("VIVZ", "onTabReselected at "+" position "+tab.getPosition()+" name "+tab.getText());
}
public void onTabSelected1(Tab tab, FragmentTransaction ft) {
Log.d("VIVZ", "onTabSelected at "+" position "+tab.getPosition()+" name "+tab.getText());
}
public void onTabUnselected1(Tab tab, FragmentTransaction ft) {
Log.d("VIVZ", "onTabUnselected at "+" position "+tab.getPosition()+" name "+tab.getText());
}
class MyAdapter extends FragmentPagerAdapter
{
public MyAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
public Fragment getItem(int arg0) {
Fragment fragment=null;
if(arg0==0)
{
fragment=new FragmentA();
}
if(arg0==1)
{
fragment=new FragmentB();
}
if(arg0==2)
{
fragment=new FragmentA();
}
return fragment;
}
@Override
public int getCount() {
return 3;
}
}
android.app.Fragment
is different from android.support.v4.app.Fragment
and hence the conflictIt may be happening because your FragmentA
class may be extending Fragment (i.e may be importing) old android.app.Fragment
and the one you posted is extending the fragment class from import android.support.v4.app.Fragment
;
See this : Difference between android.app.Fragment and android.support.v4.app.Fragment
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments