android layout is not displaying - android

I know its probably something simple I am missing here, but for some reason I can't seem to get my layout to display when I run my app using the emulator. Any feedback would be great. Thanks
my fragment
package com.pctoolman.planme.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class PlanMeMainFragment extends Fragment {
private Button mNewButton, mExistingButton;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.planme_main_fragment, container, false);
mNewButton = (Button)v.findViewById(R.id.new_event_button);
mNewButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(getActivity(), NewEventSetupActivity.class);
getActivity().startActivity(myIntent);
}
});
return v;
}
}
my layout file:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#ff3a0b">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="#string/plan_me"
android:textSize="36dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center|top"
android:textAlignment="center"
android:textColor="#2c58ff"
android:id="#+id/textView">
</TextView>
</LinearLayout>
<Button
android:id="#+id/new_event_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:padding="5dp"
android:text="#string/new_event"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp" />
<Button
android:id="#+id/existing_event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dp"
android:text="#string/existing_event"
android:layout_centerHorizontal="true"
android:layout_marginTop="260dp"/>
</RelativeLayout>
here is the activity file
package com.pctoolman.planme.app;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
public class PlanMeMainActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.planme_main_activity);
}
}

You should make a transatcion via FragmentManager to show your fragment in the activity. Suppose you have container (FrameLayout, for example) with id = fragment_container in your planme_main_activity.xml. If so, you should add the following after setContentView(R.layout.planme_main_activity);:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, new PlanMeMainFragment())
.commit();
But if you declared fragment directly in XML, please post your planme_main_activity.xml

Maybe it's because you haven't positioned the buttons properly. It's easy to move things around in a relative layout. You don't need to use gravity. You can use:
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_above="#+id/btn"
android:layout_below="#+id/btn"
I'm assuming you cut out the closing tag for the RL.

Related

Action_Call inside a TextView which is in a fragment

i know i can make textviews clickable so i can let the user call a number with an intent. but how do i achieve this when inside a fragment. i have multiple fragments and telephone numbers in my string.xml. every fragment has a telephone number, for example the code for one of my fragments:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Simmering extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.simmering_layout, container, false);
}
}
and here the xml for this class (fragment):
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="at.co.ccc.mondel.Simmering" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="#string/add_sim" />
<TextView
android:id="#+id/call_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:clickable="true"
android:text="#string/tel_sim" />
</FrameLayout>
please help me, thank you!
I am assuming you are having trouble finding the Text View in that case you can try the following way.
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Simmering extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.simmering_layout, container, false);
// Here you can access the edit text like this
mTextView = (EditText) rootView.findViewById(R.id.call_sim);
return rootView;
}
}

Call an activity from a listViewItem Without losing the tabNavigation

I'm noob on android development, and im trying to do a simple app, for details about certain products and stuff.
i have the the following layout:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="#+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
There are 2 tabs on that tabHost navigation, each one extends fragment like this
package co.com.smartmedia.vademecumtg;
import co.com.smartmedia.vademecumtg.R;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class LineasTab extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab2, container, false);
}
}
In the first tab of that navigation i have a listView, and each item of that list, must call another activity that will show details about it.
im calling a new activity by calling this method from an itemClickListener:
public void intentForMedView(int pos){
Log.w("debbuging", "start");
Intent intent = new Intent(getActivity().getApplicationContext(), MedViewActivity.class);
intent.putExtra(EXTRA_MEDTITLE, array_sort.get(pos).getNombre());
intent.putExtra(EXTRA_MEDCONTENT, array_sort.get(pos).getLinea());
Log.w("debbuging", "send intent"+intent);
startActivity(intent);
}
and the activity that i'm calling is the following:
package co.com.smartmedia.vademecumtg;
import co.com.smartmedia.vademecumtg.R;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MedViewActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_med_view);
Intent intent = getIntent();
String title = intent.getStringExtra(MedicamentosTab.EXTRA_MEDTITLE);
setTitle(title);
TextView text = (TextView) findViewById(R.id.text);
String lineName = intent.getStringExtra(MedicamentosTab.EXTRA_MEDCONTENT);
text.setText(lineName);
}
}
My problem is:
When the detail activity is shown, my navigation Disappears (the tabHost navigation), and i don't want it....
some tips or ways to do it ?
thaks...
I got the answer now, The way to accomplish this architecture, is to use FragmentTransaction
http://developer.android.com/guide/components/fragments.html
Cause it isn't necessary another activity... just play with the fragments of the UI.
FragmentManager fragmentManager = getFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
And take care with the android version cause android.support.v4.app.FragmentManager cannot cast to the android.app.FragmentManager
Hope this be usefull

Facing Issues when working with fragment

I have to create an application in which I have to work with Fragment.
In the MainActivity, there is a webView. From the SecondActivity I
have starting using Fragment.
Here is the code of SecondActivity:
package com.dev.testapp;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
public class Second extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
public void choosefragment(View view) {
Fragment fg;
if(view == findViewById(R.id.secondbtn2)) {
fg = new SecondFragment();
}
else
{
fg = new FirstFragment();
}
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.frag1, fg);
fragmentTransaction.commit();
}
}
Hhere is its second.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff" >
<Button
android:id="#+id/secondbtn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="first fragment"
android:onClick="chooseFragment" />
<Button
android:id="#+id/secondbtn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="second fragment"
android:onClick="chooseFragment"/>
<fragment
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.dev.testapp.fragment1"
android:id="#+id/frag1"
/>
</LinearLayout>
After that I created two more classes for Fragments as it is required
code of FirstFragment:
package com.dev.testapp;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FirstFragment extends Fragment{
public View onCreate(LayoutInflater inflater,
ViewGroup container , Bundle savedInstanceState) {
//Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment1,container, false);
}
}
And here is the SecondFragment:
package com.dev.testapp;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class SecondFragment extends Fragment{
public View onCreate(LayoutInflater inflater,
ViewGroup container , Bundle savedInstanceState) {
//Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment2,container, false);
}
}
When I am done with all this, my SecondActivity is showing an error that I don't know how to handle:
As noted in previous answers, your problem is incorrect Fragment library for FirstFragment.
Change line 5 of FirstFragment.java:
import android.support.v4.app.Fragment;
to:
import android.app.Fragment;
Your second fragment is of the type android.app.Fragment while your first fragment is android.support.v4.app.Fragment.
your activity use this import android.app.Fragment;
your fragment is import android.support.v4.app.Fragment;
So you either have both extending the Fragment in the app package or in the support library

Android Activity not Responding

I have 3 activities in my app and when user press next button, next activity is shown to user, Now everything works fine except when it reaches the last activity i.e. when user presses next on 2nd last activity, an error message is shown that app has stopped working and there is no error in LogCat, following is the .java file of my Final Activity
package com.example.first;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.os.Build;
public class FinalActivity extends ActionBarActivity {
TextView name,address,phone,email,dob,matg,mati,interg,interi,graddeg,gradi,cgpa,skills;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);
name=(TextView)findViewById(R.id.fname);
address=(TextView)findViewById(R.id.faddress);
phone=(TextView)findViewById(R.id.fphone);
email=(TextView)findViewById(R.id.femail);
dob=(TextView)findViewById(R.id.fdob);
matg=(TextView)findViewById(R.id.matricgrade);
mati=(TextView)findViewById(R.id.matricinst);
interg=(TextView)findViewById(R.id.intergrade);
interi=(TextView)findViewById(R.id.interinst);
graddeg=(TextView)findViewById(R.id.graddegree);
cgpa=(TextView)findViewById(R.id.gradcgpa);
skills=(TextView)findViewById(R.id.iskills);
Intent in=getIntent();
UserBO bo=new UserBO();
bo.name=in.getStringExtra("name");
bo.address=in.getStringExtra("address");
bo.email=in.getStringExtra("email");
bo.phone=in.getStringExtra("phone");
bo.dob=in.getStringExtra("dob");
bo.mg=in.getStringExtra("mgrade");
bo.mi=in.getStringExtra("minst");
bo.ig=in.getStringExtra("igrade");
bo.ii=in.getStringExtra("iinst");
bo.gg=in.getStringExtra("gdeg");
bo.gi=in.getStringExtra("ginst");
bo.cgpa=in.getStringExtra("cgpa");
bo.skills=in.getStringExtra("skills");
name.setText("Name : "+bo.name);
address.setText("Address : "+bo.address);
email.setText("Email : "+bo.email);
phone.setText("Phone : "+bo.phone);
dob.setText("DOB : "+bo.dob);
matg.setText("Matric Grade : "+bo.mg);
mati.setText("Institution : "+bo.mi);
interg.setText("Inter Grade : "+bo.ig);
interi.setText("Institution : "+bo.ii);
graddeg.setText("Graduation Degree : "+bo.gg);
gradi.setText("Institution : "+bo.gi);
skills.setText("Skills : "+bo.skills);
}
}
Here is the xml file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.first.FinalActivity"
tools:ignore="MergeRootFrame" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/faddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/fphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/femail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/fdob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/matricgrade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/matricinst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/intergrade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/interinst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/graddegree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/gradinst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/gradcgpa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/iskills"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/hobbies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
</FrameLayout>
Here i'm calling the final activity
package com.example.first;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;
public class Activity2 extends ActionBarActivity {
Button next3;
EditText s1,s2,s3,s4,s5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
next3=(Button)findViewById(R.id.next3);
s1=(EditText)findViewById(R.id.sk1);
s2=(EditText)findViewById(R.id.sk2);
s3=(EditText)findViewById(R.id.sk3);
s4=(EditText)findViewById(R.id.sk4);
s5=(EditText)findViewById(R.id.sk5);
next3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in=getIntent();
UserBO bo=new UserBO();
bo.name=in.getStringExtra("name");
bo.address=in.getStringExtra("address");
bo.email=in.getStringExtra("email");
bo.phone=in.getStringExtra("phone");
bo.dob=in.getStringExtra("dob");
bo.mg=in.getStringExtra("mgrade");
bo.mi=in.getStringExtra("minst");
bo.ig=in.getStringExtra("igrade");
bo.ii=in.getStringExtra("iinst");
bo.gg=in.getStringExtra("gdeg");
bo.gi=in.getStringExtra("ginst");
bo.cgpa=in.getStringExtra("cgpa");
bo.skills+=s1.getText().toString()+","+s1.getText().toString()+","+s2.getText().toString()+","+s3.getText().toString()+","+s4.getText().toString()+","+s5.getText().toString();
Intent i=new Intent(getApplicationContext(),FinalActivity.class);//this,same
System.out.println(bo.name);
i.putExtra("name", bo.name);
i.putExtra("address", bo.address);
i.putExtra("email", bo.email);
i.putExtra("phone", bo.phone);
i.putExtra("dob", bo.dob);
i.putExtra("mgrade", bo.mg);
i.putExtra("minst", bo.mi);
i.putExtra("igrade", bo.ig);
i.putExtra("iinst", bo.ii);
i.putExtra("gdeg", bo.gg);
i.putExtra("ginst", bo.gi);
i.putExtra("cgpa", bo.cgpa);
i.putExtra("skills", bo.skills);
startActivity(i);
}
});
}
Here is Activity1
package com.example.first;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;
public class Activity1 extends ActionBarActivity {
Button next2;
EditText matGrade,matInst,iGrade,iInst,gDegree,gInst,gCgpa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity1);
next2=(Button)findViewById(R.id.next2);
matGrade=(EditText)findViewById(R.id.mgrade);
matInst=(EditText)findViewById(R.id.minst);
iGrade=(EditText)findViewById(R.id.igrade);
iInst=(EditText)findViewById(R.id.iinst);
gDegree=(EditText)findViewById(R.id.gdegree);
gInst=(EditText)findViewById(R.id.ginst);
gCgpa=(EditText)findViewById(R.id.cgpa);
next2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in=getIntent();
UserBO bo=new UserBO();
bo.name=in.getStringExtra("name");
bo.address=in.getStringExtra("address");
bo.email=in.getStringExtra("email");
bo.phone=in.getStringExtra("phone");
bo.dob=in.getStringExtra("dob");
bo.mg=matGrade.getText().toString();
bo.mi=matGrade.getText().toString();
bo.ig=iGrade.getText().toString();
bo.ii=iGrade.getText().toString();
bo.gg=gDegree.getText().toString();
bo.gi=gDegree.getText().toString();
bo.cgpa=gDegree.getText().toString();
Intent i=new Intent(getApplicationContext(),Activity2.class);//this,same
i.putExtra("name", bo.name);
i.putExtra("address", bo.address);
i.putExtra("email", bo.email);
i.putExtra("phone", bo.phone);
i.putExtra("dob", bo.dob);
i.putExtra("mgrade", bo.mg);
i.putExtra("minst", bo.mi);
i.putExtra("igrade", bo.ig);
i.putExtra("iinst", bo.ii);
i.putExtra("gdeg", bo.gg);
i.putExtra("ginst", bo.gi);
i.putExtra("cgpa", bo.cgpa);
startActivity(i);
}
});
}
}
Here is the main Activity
package com.example.first;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
Button next1;
EditText name,address,email,phone,date;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
next1=(Button)findViewById(R.id.next1);
name=(EditText)findViewById(R.id.name);
address=(EditText)findViewById(R.id.address);
email=(EditText)findViewById(R.id.email);
phone=(EditText)findViewById(R.id.phone);
date=(EditText)findViewById(R.id.date);
next1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
UserBO bo=new UserBO();
bo.name=name.getText().toString();
bo.address=address.getText().toString();
bo.email=email.getText().toString();
bo.phone=phone.getText().toString();
bo.dob=date.getText().toString();
Intent i=new Intent(getApplicationContext(),Activity1.class);//this,same
i.putExtra("name", bo.name);
i.putExtra("address", bo.address);
i.putExtra("email", bo.email);
i.putExtra("phone", bo.phone);
i.putExtra("dob", bo.dob);
startActivity(i);
}
});
}
}
Please help me find the mistake
I think you have null pointer exception. Maybe one of your controls is missed in your xml layout. For example you are finding "next1" in your code and using its setOnClickListener method while it is not defined in you xml layout so its object is null.
I recommend you put the content of onCreate method in a try-catch and debug your application.

No output from fragments in android.

Using fragments for the first time. As fragment in itself an activity, going by the documentation, I think I've written it correctly in the manifest.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/example_fragment"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="com.test.methods.ExampleFragment"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
<FrameLayout android:id="#+id/details" android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>
My fragment:
package com.test.methods;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.crumbin.main.R;
public class ExampleFragment extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
setListAdapter(new ArrayAdapter<String>(getActivity(),
R.id.list,
Shakespeare.TITLES));
return inflater.inflate(R.layout.example_fragment, container, false);
}
}
My Activity:
package com.test.methods;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class DemoUserActivity extends FragmentActivity{
protected void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (savedInstanceState == null)
{
ExampleFragment details = new ExampleFragment();
details.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(
android.R.id.content,details).commit();
}
}
}
My intent:
intent = new Intent().setClass(this, DemoUserActivity.class);
spec = tabHost.newTabSpec("list").setIndicator("FragmentTest",
res.getDrawable(R.drawable.icon_list_tab))
.setContent(intent);
tabHost.addTab(spec);
I get no output out of this. I tried debugging but it is not even reaching my activity file.
No Activity is different thing, and Fragment is different, you can use these to create your application moduler, and replace one with another with minimum efforts, but can not use as a replacement of other, if You want to use a fragment, you need to declare an activity, in that activity you need to add your fragment, individual fragment without Activity can not be used.

Categories

Resources