I have to call a fragment (Page1) from here...
protected void onPostExecute(Void args) {
Intent intentx;
intentx = new Intent(HomeFragment.this.getActivity(),Main.class);
intentx.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentx);
}
I my program i have Main class which looks like this
public class Main extends FragmentActivity implements
ActionBar.TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "Express(1 Day)", "Premium (2 Day)", "Normal (3+ Days)" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tab);
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
//actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
This class will invoke Page1,Page2,Page3
Inside Page 1 the code is this
public class Page1 extends Fragment {
public static ArrayList<String> strArr;
public static ArrayList<ArrayList<String>> content;
public static ArrayAdapter<String> adapter;
LinearLayout ll;
View format;
float days_to_del;
int[] no_of_count= new int[20];
int count;
int x;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.page1, container, false);
// super.onResume();
//View rootView = inflater.inflate(R.layout.page1, container, false);
for(int j=0;j<10;j++)
{
days_to_del=Float.parseFloat(""+Lib.result[j][0].toString());
if(days_to_del==2.0)
{
no_of_count[x]=j;
x++;
count++;
}
}
for(int m=0;m<count;m++)
{
ll = (LinearLayout) rootView.findViewById(R.id.parent);
LayoutInflater vi = (LayoutInflater) Page1.this.getActivity().getApplicationContext().getSystemService(Page1.this.getActivity().LAYOUT_INFLATER_SERVICE);
format = inflater.inflate(R.layout.page1, null);
ll.addView(format);
//Lib.ShowAlertMessage(Page1.this.getActivity().getApplicationContext(), "", ""+format.getId());
if(Lib.result[no_of_count[m]][2].toString().equals("First Flight Couriers"))
{
ImageView imageView1=(ImageView)rootView.findViewById(R.id.imageView1);
String uri = "@drawable/first_flight";
int imageResource = getResources().getIdentifier(uri, null, Page1.this.getActivity().getApplicationContext().getPackageName());
Drawable res = getResources().getDrawable(imageResource);
imageView1.setImageDrawable(res);
}
else if(Lib.result[no_of_count[m]][2].toString().equals("SkyNet WorldWide Express"))
{
ImageView imageView1=(ImageView)rootView.findViewById(R.id.imageView1);
String uri = "@drawable/skynet";
int imageResource = getResources().getIdentifier(uri, null, Page1.this.getActivity().getApplicationContext().getPackageName());
Drawable res = getResources().getDrawable(imageResource);
imageView1.setImageDrawable(res);
}
else if(Lib.result[no_of_count[m]][2].toString().equals("The Professional Couriers"))
{
ImageView imageView1=(ImageView)rootView.findViewById(R.id.imageView1);
String uri = "@drawable/professional";
int imageResource = getResources().getIdentifier(uri, null, Page1.this.getActivity().getApplicationContext().getPackageName());
Drawable res = getResources().getDrawable(imageResource);
imageView1.setImageDrawable(res);
}
else if(Lib.result[no_of_count[m]][2].toString().equals("The Professional Couriers"))
{
ImageView imageView1=(ImageView)rootView.findViewById(R.id.imageView1);
String uri = "@drawable/professional";
int imageResource = getResources().getIdentifier(uri, null, Page1.this.getActivity().getApplicationContext().getPackageName());
Drawable res = getResources().getDrawable(imageResource);
imageView1.setImageDrawable(res);
}
TextView textView2=(TextView)rootView.findViewById(R.id.textView2);
textView2.setText("Rupees");
}
if(format.getId()==1)
{
ll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intentx;
intentx = new Intent(Page1.this.getActivity(), From.class); //mContext is a Context variable.
intentx.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
});
}
if(format.getId()==2)
{
ll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intentx;
intentx = new Intent(Page1.this.getActivity(), To.class);
intentx.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
});
}
return rootView;
}
public void onResume(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
}
}
My Issue 1. I use these variables(Lib.results[][]) in the PostExecute They are available ( I dont require here) 2. In the fragment Page1 i am not able access the Lib.results[][] , as soon as it enters the Page1 the value of result[][] is null as the value is not updated(this is what I guessed would have hapened) 3. The results based on the values will go to respective fragments (Page1,Page2,Page3)
Question Am i calling the fragment activity the rightway?? does intent work this way or is there any other method.