Android Fragment behaving weird - android

The activity_main.xml is like this
<LinearLayout 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" >
<Button
android:id="#+id/button_one_activity_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Button"
/>
<fragment
android:name="fragments.FirstFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/first_fragment" />
<Button
android:id="#+id/button_two_activity_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Button"
/>
</LinearLayout>
The main activity class is like this
package com.example.testfragmentshoneycomb;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
first_fragment.xml is like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/grey" >"
<TextView
android:id="#+id/text_view_one_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text View one" />
<TextView
android:id="#+id/text_view_two_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text View two" />
<TextView
android:id="#+id/text_view_three_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text View three" />
</LinearLayout>
FirstFragment class is like this
package fragments;
import com.example.testfragmentshoneycomb.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FirstFragment extends Fragment{
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.first_fragment, container, false);
return view;
}
}
It shows only first button and nothing else on the screen. If I remove the first button from activity_main.xml it shows the fragment but doesn't show the second button.
Min SDK version is 11 and build target is android 4.1

set android:orientation="vertical" in your activity layout.

Its because by default LinearLayout's orientation is horizontal. Therefore the whole screens width is captured by the First Button and Fragment.
Are you sure you want to see it like?
First_Button Fragment Second_Button
If Yes the use layout_weight. If No then give orientation=vertical to LinearLayout which will show your layout output as
First_Button
Fragment
Second_Button

set LinearLayout orientation to vertical, it's horizontal by default.
read docs carefully

Use the following layout :
<LinearLayout 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"
android:orientation="vertical" >
<Button
android:id="#+id/button_one_activity_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Button"
/>
<fragment
android:name="fragments.FirstFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/first_fragment" />
<Button
android:id="#+id/button_two_activity_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Button"
/>
</LinearLayout>

Related

Why am I not able to switch between two Fragments in Android

I have tried everything but still, I am not able to change Fragments from CalculatorP1 to Calculator_P2. When I click the button only one Fragment is shown but when I click the button again the second Fragment does not show itself in the APP. I tried everything and I also tried to use TWO BUTTONS bt only one Fragment Shows itself. The second Fragment doesn't show itself. If I switch the fragments only the first Fragment shows bt the 2nd fragment doesn't show itself.
Please help.
My App... See how the button text changes but the Fragment remains the same
My XML codes are given Below:
<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:orientation="vertical">
<Button
android:id="#+id/bn_f1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment 1" />
<Button
android:id="#+id/bn_f2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment 2" />
</LinearLayout>
<LinearLayout
android:id="#+id/fragment_container"
android:layout_width="276dp"
android:layout_height="350sp"
android:layout_alignParentBottom="true"
android:orientation="vertical"></LinearLayout>
My Activity.java is given below:
package com.example.sudeepsarker.sudeepcalculatorvv;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button bn_fragment;
private boolean status= false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bn_fragment = findViewById(R.id.bn_f1);
bn_fragment.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
android.app.FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if(!status){
CalculatorP1 p1 = new CalculatorP1();
fragmentTransaction.add(R.id.fragment_container,p1);
fragmentTransaction.commit();
bn_fragment.setText("Fragment 2");
status=true;
}
else{
Calculator_P2 p2= new Calculator_P2();
fragmentTransaction.add(R.id.fragment_container,p2);
fragmentTransaction.commit();
bn_fragment.setText("Fragment 1");
status=false;
}
}
});
}
}
My Fragment one xml file:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="350sp"
tools:context=".CalculatorP1"
android:background="#8F3A1E"
>
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My first Part of calculator"
android:textColor="#ffffff"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>
My Fragment Two XML File:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="350sp"
tools:context=".CalculatorP1"
android:background="#077715"
>
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My Second Part of calculator"
android:textColor="#ffffff"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:textAppearanceLarge"
/>

How to add 2 fragments dynamically in a single layout?

I want to add 2 fragments in a single layout like this:
I was able to do it using static fragment method but not able to do it dynamically. I want to target API 14 and above.
Here is the code:
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/new_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:id="#+id/my_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
</LinearLayout>
fragment1.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00ff00"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fragment first"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"
/>
</LinearLayout>
fragment2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#0000ff">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fragment second"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="1"
/>
</LinearLayout>
fragment1.java:
package org.hinduismfacts.www.dynamicfragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Rahul on 07-08-2017.
*/
public class fragment1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment1,container, false);
}
}
fragment2.java:
package org.hinduismfacts.www.dynamicfragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by Rahul on 07-08-2017.
*/
public class fragment2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment2,container, false);
}
}
MainActivity.java:
package org.hinduismfacts.www.dynamicfragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
// Create new fragment and transaction
Fragment newFragment = new fragment1();
Fragment myFragment = new fragment2();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.add(R.id.new_placeholder, newFragment);
transaction.add(R.id.my_placeholder, myFragment);
transaction.commit();
}
}
In the output I am getting only first fragment displayed. The second fragment is not getting added. Output:
Can you please tell me what is going wrong?
please added android:layout_weight="1"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/new_placeholder"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent">
</LinearLayout>
<LinearLayout
android:id="#+id/my_placeholder"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
>
</LinearLayout>
</LinearLayout>
You need layout weight android:layout_weight for both your frame layout
try below XML changes
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/new_placeholder"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:id="#+id/my_placeholder"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
The problem is in your activity_main.xml.
Use android:layout_weight="1" for each of your fragments container to show both of them on the screen.
Also fill_parent is deprecated. Consider using match_parent instead

Android OnClick fails every new project

First post. I'm following a few courses on Android programming so fairly new but not a complete newbie. I have a background in programming from long ago..
For some odd reason, older projects have the OnClick running fine but every project I created today, with either Genymotion or AVD the OnClick never fires even in the following barebone example I created.
https://www.dropbox.com/s/js1qh263vldte0z/deleteme.zip?dl=0
Here's the original project I'm working on which I can't even click on the buttons (as if there's a transparency in front or something).
If someone can explain why when I open older projects based on 22 everything works but running now on 23 (with 16 as backward) OnClick doesn't work that'd be very nice of you. Thanks!
The Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="ca.shaarable.planetxerox.admin_add_products_hardware">
<LinearLayout
android:orientation="vertical"
android:id="#+id/admin_add_printer_first"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<TextView
android:id="#+id/admin_add_printer_tv_name"
android:text="#string/admin_add_printer_tv_name"
android:textSize="12sp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/admin_add_printer_et_name"
android:text="#string/admin_add_printer_et_name"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="#+id/admin_add_printer_second"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.65">
<TextView
android:id="#+id/admin_add_printer_tv_thumbnail"
android:text="#string/admin_add_printer_tv_thumbnail"
android:textStyle="italic"
android:layout_marginBottom="5dp"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/admin_add_printer_image"
android:src="#drawable/igen5"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="#+id/admin_add_printer_third"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15">
<LinearLayout
android:id="#+id/admin_add_printer_sublayout"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_weight="1"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/admin_add_printer_CANCEL"
android:text="#string/admin_add_printer_CANCEL"
android:background="#F99F1C"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/admin_add_printer_ADD"
android:text="#string/admin_add_printer_ADD"
android:background="#2ABDBA"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And here's the code for the class:
package ca.shaarableapps.presssupport;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class AdminAddPrinter extends AppCompatActivity implements View.OnClickListener
{
private EditText printerName;
private ImageView printerThumbnail;
private Button cancelBtn, addBtn;
private static final String TAG = "MyActivity";
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_add_printer);
printerName = (EditText)findViewById(R.id.admin_add_printer_et_name);
printerThumbnail = (ImageView)findViewById(R.id.admin_add_printer_image);
cancelBtn = (Button)findViewById(R.id.admin_add_printer_CANCEL);
addBtn = (Button)findViewById(R.id.admin_add_printer_ADD);
}
#Override
public void onClick(View v)
{
Log.v(TAG, "Nooooooooooooo");
switch (v.getId())
{
case R.id.admin_add_printer_ADD:
addBtn.setText("Good Job");
break;
}
}
}
This is the layout as seen by the user...
Try to add .setOnClickListener(this); inside onCreate(...) method.
protected void onCreate(Bundle savedInstanceState){
...
addBtn.setOnClickListener(this);
}
Hope this help
The problem is here in you code.
<Button
android:id="#+id/admin_add_printer_ADD"
android:text="#string/admin_add_printer_ADD"
android:background="#2ABDBA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onClick" // add this line
/>

Error in MainActivity when implementing TabActivity

i want a page with text on top(EditText) then image (in FragmentLayout) and then two tabs below that image.
my output is not showing any tab in output but i have written code to implement tabs.
this code is notshowing any error and in output i mam not getting any tab in output
i am not getting correct output and this is not even showing any error
i tried it without extending TabActivity also (only with extens Activity) but still output is same whose image is loaded above
Code of activity_main.xml is
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tbol"
android:layout_width="250dp"
android:layout_height="30dp"
android:text="#string/heading"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#F00"
android:textSize="25sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#drawable/leaf" >
</FrameLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
code of MainActivity.java is
package com.example.tabhost;
import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
#SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
TabHost th;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
th=getTabHost();
//For desc tab
TabSpec descspec=th.newTabSpec("Description");
descspec.setIndicator("Description", null);
Intent firstintent=new Intent(this, DecsriptionTab.class);
descspec.setContent(firstintent);
//For Information Tab
TabSpec infospec=th.newTabSpec("Information");
infospec.setIndicator("Information", null);
Intent secondintent=new Intent(this, Info_Tab.class);
descspec.setContent(secondintent);
}
}
this is code of 2 .xml files
desc_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:text="This is desc tab"
android:padding="15dp"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
info_layout
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:text="This is info tab"
android:padding="15dp"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
This is code of corresponding java files
DecsriptionTab.java
package com.example.tabhost;
import android.app.Activity;
import android.os.Bundle;
public class DecsriptionTab extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.desc_layout);
}
}
Info_Tab.java
package com.example.tabhost;
import android.app.Activity;
import android.os.Bundle;
public class Info_Tab extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.info_layout);
}
}

Android - Sliding Fragments

I'm trying to implement the sliding animation to transit from fragment1 to fragment2.
I'm using setCustomAnimations method. And I understand I need to use the frame method in order to replace fragments.
My code:
package com.example.fragmentss;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity implements MyListFragment.OnItemSelectedListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_rsslist_overview);
}
// if the wizard generated an onCreateOptionsMenu you can delete
// it, not needed for this tutorial
#Override
public void onRssItemSelected(String link) {
}
}
activity_main.xml
<?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="horizontal" >
<fragment
android:id="#+id/listFragment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
class="com.example.fragmentss.MyListFragment" ></fragment>
<FrameLayout android:id="#+id/details" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground" />
</LinearLayout>
MyListFragment class
package com.example.fragmentss;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class MyListFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_rsslist_overview,
container, false);
return view;
}
public void onClick2(View view) {
switch (view.getId()) {
case R.id.button2:
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
DetailFragment newFragment = DetailFragment.newInstance();
ft.replace(R.id.details, newFragment, "mylistFragment");
// Start the animated transition.
ft.commit();
break;
}
}
} ~
fragment_rssitem_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Goto 2"
android:onClick="onClick1"/>
<TextView
android:id="#+id/detailsText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="20dip"
android:text="Frag 1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dip" />
</LinearLayout>
fragment_rsslist_overview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Goto 1"
android:onClick="onClick2" />
<TextView
android:id="#+id/textView1"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:text="Frag 2"
android:textSize="30dip"/>
</LinearLayout>
I guess what you are trying to implement can very easily be implemented by a ViewPager
ViewPager is a custom component that was introduced to implement easy and smooth switching between fragments . Android Documentation has a very good and easy to understand example to understand it's use Take a look at http://developer.android.com/training/animation/screen-slide.html .You can also see similar questions that have been answered
Example/Tutorial for ViewPager and Fragments and
How to use Android ViewPager?

Categories

Resources