android layout animation bottom to top - android-studio

I have created a layout in Android . how to give animation from bottom to top and top to bottom when i pressed button?
Please find my code below.
Main Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(
MainActivity.this, R.style.Theme_AppCompat);
View bottomSheetView = LayoutInflater.from(getApplicationContext())
.inflate(R.layout.bottom_sheet,
(LinearLayout)findViewById(R.id.bottomSheetContainer));
bottomSheetDialog.setContentView(bottomSheetView);
overridePendingTransition( R.anim.slide_in_top, R.anim.slide_in_bottom);
bottomSheetDialog.show();
}
});
}
Bottom Layout
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/bottomSheetContainer"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
android:background="#color/white">

Related

Spinner has data but doesn't have any preview text/selected text

Spinner has data but doesn't have any preview text/selected text I try various things and still doesn't show any text
Im trying to use spinner for some data and I successfully populated some list for spinner data but it doesn't show any in the spinner.
I also try various things i saw from the net and it didnt work.
Here is the link where I based my code for spinner: https://www.youtube.com/watch?v=j7P5k-dHS9Y
JAVA CODE:
public class SpinnerSample extends AppCompatActivity {
Spinner spinner;
boolean isSpinnerTouched = false;
DatabaseReference databaseReference;
String[] status = {"Not Available", "Available", "Under Maintenance"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spinner_sample);
spinner = findViewById(R.id.spiiner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(SpinnerSample.this, R.layout.style_spinner, status);
adapter.setDropDownViewResource(R.layout.style_spinner);
spinner.setAdapter(adapter);
databaseReference = FirebaseDatabase.getInstance().getReference();
spinner.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
isSpinnerTouched = true;
return false;
}
});
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String value = adapterView.getItemAtPosition(i).toString();
if (!isSpinnerTouched) {
Toast.makeText(SpinnerSample.this, "No Selected", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SpinnerSample.this, value, Toast.LENGTH_SHORT).show();
}
}
});
}
}
XML CODE:
<LinearLayout 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"
android:orientation="vertical"
tools:context=".SpinnerSample">
<Spinner
android:id="#+id/spiiner"
android:layout_width="240dp"
android:background="#ff0"
android:layout_height="40dp"
android:textColor="#000"
android:hint="Current Password"
android:layout_marginTop="10dp"/>
</LinearLayout>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:text="A"
android:padding="20dp"
android:layout_height="match_parent"
android:textColor="#000"
android:textColorHint="#1e7591">
</TextView>

My app Crashes after creating a button to a RelativeLayout

I want to create a viewpager that uses relative layout.
but before that screen pops out, i have a constraintlayout screen.
So i create a button to direct me to that viewpager, but app crashes and i dont know why...
Java:
public class TelaPrincipal extends AppCompatActivity {
private Button bt_to_treinos;
FirebaseFirestore db = FirebaseFirestore.getInstance();
String usuarioID;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tela_principal);
getSupportActionBar().hide();
IniciarComponentes();
//THIS BUTTON OVER HERE
bt_to_treinos.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(TelaPrincipal.this,SlideAdapter.class);
startActivity(intent);
}
});
}
}
i did 2 RelativeLayouts:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/slide_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="80dp"
android:src="#drawable/segunda" />
<TextView
android:id="#+id/slide_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="350dp"
android:layout_marginLeft="110dp"
android:text="Segunda"
android:textColor="#color/white"
android:textSize="50sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/slide_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="500dp"
android:text="#string/example"
android:textColor="#color/white"
android:textSize="15sp"
android:textStyle="bold" />
Second one:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".treinos"
android:background="#drawable/background"
>
<androidx.viewpager.widget.ViewPager
android:id="#+id/slideViewPager"
android:layout_width="match_parent"
android:layout_height="650dp" />
this screen should appear but crashes:
public class treinos extends AppCompatActivity {
private ViewPager mSlideViewPager;
private LinearLayout mDotLayout;
private TextView[] mDots;
private SlideAdapter sliderAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_treinos);
getSupportActionBar().hide();
mSlideViewPager = findViewById(R.id.slideViewPager);
sliderAdapter = new SlideAdapter(this);
mSlideViewPager.setAdapter(sliderAdapter);
}}
Slidepager class other java code:
public class SlideAdapter extends PagerAdapter {
Context context;
LayoutInflater layoutInflater;
public SlideAdapter(Context context){
this.context = context;
}
//Arrays
public int [] slide_images = {
R.drawable.segunda,
R.drawable.terca,
R.drawable.quarta,
R.drawable.quinta,
R.drawable.sexta,
R.drawable.sabado,
R.drawable.domingo
};
public String[] slide_headings = {
"Segunda",
"Terça",
"Quarta",
"Quinta",
"Sexta",
"Sábado",
"Domingo"
};
public String[] slide_descs = {
"Btest1",
"test 2",
"test 3",
"test 4",
"test 5",
"test 6",
"test 7 "
};
#Override
public int getCount() {
return slide_headings.length;
}
#Override
public boolean isViewFromObject(View view, Object o) {
return view == (RelativeLayout) o;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater)
context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.slide_layout, container, false);
ImageView slideImageView = (ImageView) view.findViewById(R.id.slide_image );
TextView slideHeading = (TextView) view.findViewById(R.id.slide_heading );
TextView slideDescription = (TextView) view.findViewById(R.id.slide_desc);
slideImageView.setImageResource(slide_images[position]);
slideHeading.setText(slide_headings[position]);
slideDescription.setText(slide_descs[position]);
container.addView(view);
return view;
}
#Override
public void destroyItem(#NonNull ViewGroup container, int position, #NonNull Object object) {
container.removeView((RelativeLayout) object);
}}
Thankyou Everyone

Cant add more websites on click of ImageView

I want to add 3 Imageview with different url, i have tried adding it but it was not possible for me. Any suggestions guys?It would be great if you guys help me out on this.
Main activity
public class main extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ImageView img = (ImageView) findViewById(R.id.amazon);
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(main.this, MainActivity.class);
intent.setData(Uri.parse("http://www.amazon.in"));
startActivity(intent);
}
});
}
XML layout for main activity
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="#drawable/amazon"
android:layout_marginTop="19dp"
android:id="#+id/amazon"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="11dp" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="#drawable/flipkart"
android:id="#+id/flipkart"
android:layout_marginStart="31dp"
android:layout_alignTop="#+id/amazon"
android:layout_toEndOf="#+id/amazon" />
<TextView
android:text="Amazon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/amazon"
android:layout_toStartOf="#+id/flipkart"
android:id="#+id/tvam" />
<TextView
android:text=" flipkart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/flipkart"
android:layout_alignStart="#+id/flipkart"
android:id="#+id/tvflip" />
Web view activity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView htmlWebView = (WebView) findViewById(R.id.webView);
htmlWebView.setWebViewClient(new CustomWebViewClient());
WebSettings webSetting = htmlWebView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setDisplayZoomControls(true);
htmlWebView.loadUrl("https://amazon.in");
}
class CustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
my webview xml
<?xml version="1.0" encoding="utf-8"?>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView">
</WebView>
Here is the full code.Make one change that take your imagebutton insted of simple button .
**main.xml**
<Button
android:id="#+id/btnAmazon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AMZON" />
<Button
android:id="#+id/btnFlipkart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FLIPKART" />
<Button
android:id="#+id/btnGoogle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GOOGLE" />
**Code for java file main.java**
btnGoogle = (Button) findViewById(R.id.btnGoogle);
btnAmazon = (Button) findViewById(R.id.btnAmazon);
btnFlipkart = (Button) findViewById(R.id.btnFlipkart);
final Bundle bundle = new Bundle();
btnGoogle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(SplashActivity.this, WebviewUrl.class);
bundle.putString("URL","http://www.google.com");
intent.putExtras(bundle);
startActivity(intent);
}
});
btnAmazon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(SplashActivity.this, WebviewUrl.class);
bundle.putString("URL","http://www.amazon.in");
intent.putExtras(bundle);
startActivity(intent);
}
});
btnFlipkart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(SplashActivity.this, WebviewUrl.class);
bundle.putString("URL","https://www.flipkart.com/");
intent.putExtras(bundle);
startActivity(intent);
}
});
**xml code for MainActivity**
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_webview_url"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.pg.gymapp.activity.WebviewUrl">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</RelativeLayout>
**code for mainactivity.java**
public class MainActivity extends AppCompatActivity {
WebView webView ;
Bundle bundle ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
bundle = getIntent().getExtras();
Log.d("URL ",bundle.getString("URL"));
webView.loadUrl(bundle.getString("URL"));
webView.setWebViewClient(new CustomWebViewClient());
WebSettings webSetting = webView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setDisplayZoomControls(true);
webView.loadUrl(bundle.getString("URL"));
}
class CustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
At last make sure that you gave **internet permission** in manifest file
<uses-permission android:name="android.permission.INTERNET" />
Hope this will help you .

Fragment overlapping appbar

I have a possible overlapping fragment containing listView. The layout looks fine in the preview window, however, when I run it on device or Emulator the appbar goes missing.
Main XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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: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=".GuiseMainActivity"
android:orientation="vertical">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:id="#+id/fragmentProps"></fragment>
</RelativeLayout>
Fragment XML
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:gravity="top|center"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/propCategoryListView"></ListView>
</LinearLayout>
Main Class
public class GuiseMainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
FragmentProps fragmentProps = new FragmentProps();
fragmentTransaction.replace(android.R.id.content,fragmentProps);
fragmentTransaction.commit();
}}
Fragment Class
public class FragmentProps extends Fragment{
private View PropsFragmentView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
PropsFragmentView = inflater.inflate(R.layout.fragment_props, container, false);
String[] propsCategories ={"Recently used", "Popular", "New", "Personalities", "Moustaches / Beard", "Caps/ Hats", "Glasses", "Banners"};
ListAdapter propsCategoryListAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, propsCategories);
ListView propCategoryListView = (ListView) PropsFragmentView.findViewById(R.id.propCategoryListView);
propCategoryListView.setAdapter(propsCategoryListAdapter);
propCategoryListView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String categoryPicked = "You Picked: " + String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(getActivity(), categoryPicked, Toast.LENGTH_LONG).show();
}
});
return PropsFragmentView;
}}
Result
I found the solution, MainActivity Extends AppCompatActivity then add these lines in onCreate method:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.applogo);
getSupportActionBar().setTitle("");
Thanks guys.

How to Show Different Layouts inside Fragments

I am working with two fragments in Android Honeycomb (Tab). In the left is a ListView and in the right is a preview of the item selected from the list. When one of the buttons is clicked, I want to show different layouts on the left. How is it possible?
Thanks in advance.
You can do this, I made the same thing with use of these links, here is my code which I am sharing with you in the hope that it will be helpful for you... You will first have to create 4 layouts. 2 of which will be for landscape mode, one for portrait mode and another for tablets. You have to create a couple more folders for layouts and their name should be like layout-xlarge and layout-xlarge-port, this way you can create fragments for both mobile devices and tablets.
MasterFragment Activity:
public class MasterFragment extends ListFragment {
Boolean isDualPane;
int position;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayList<String> parkNames = new ArrayList<String>();
for (Park park : Resort.PARKS) {
parkNames.add(park.getName());
}
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, parkNames));
View detailFrame = getActivity().findViewById(R.id.detail);
isDualPane = detailFrame != null && detailFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
position = savedInstanceState.getInt("position", 0);
}
if (isDualPane) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
showDetail(position);
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("position", position);
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
showDetail(position);
}
void showDetail(int position) {
this.position = position;
if (isDualPane) {
getListView().setItemChecked(position, true);
DetailFragment detailFragment = (DetailFragment) getFragmentManager()
.findFragmentById(R.id.detail);
if (detailFragment == null || detailFragment.getIndex() != position) {
detailFragment = new DetailFragment(position);
FragmentTransaction ft = getFragmentManager()
.beginTransaction();
ft.replace(R.id.detail, detailFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
} else {
Intent intent = new Intent();
intent.setClass(getActivity(), DetailActivity.class);
intent.putExtra("position", position);
startActivity(intent);
}
}
}
Second Activity - DetailFragment Activity:
public class DetailActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_act);
Bundle bundle = getIntent().getExtras();
int position = bundle.getInt("position");
System.out.println("RR : position is : " + position);
Integer[] images = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3,
R.drawable.pic4, R.drawable.pic5, R.drawable.pic6,
R.drawable.pic7, R.drawable.pic8, R.drawable.pic9,
R.drawable.pic10, R.drawable.pic11, R.drawable.pic12,
R.drawable.pic13 };
final ImageView imgview = (ImageView) findViewById(R.id.imageView1);
imgview.setImageResource(images[position]);
// DetailFragment detailFragment = new DetailFragment(position);
// FragmentManager fm = getSupportFragmentManager();
// FragmentTransaction ft =fm.beginTransaction();
// ft.add(android.R.id.content, detailFragment).commit();
}
}
Now you have to create a third activity, MasterGridActivity for my images which I am using for showing in fragment in GridView.
public class MasterGridActivity extends Fragment {
Boolean isDualPane;
GridView gridView;
ListView listView;
int position;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.gridview, container, false);
gridView = (GridView) view.findViewById(R.id.gridViewImage);
gridView.setAdapter(new MyAdapter(view.getContext()));
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
View detailFrame = getActivity().findViewById(R.id.detail);
isDualPane = detailFrame != null && detailFrame.getVisibility() == View.VISIBLE;
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
if (!isDualPane) {
Intent intent = new Intent();
intent.setClass(getActivity(), DetailActivity.class);
intent.putExtra("position", pos);
startActivity(intent);
} else {
DetailFragment detailFragment = (DetailFragment) getFragmentManager().findFragmentById(R.id.detail);
if (detailFragment == null || detailFragment.getIndex() != pos) {
detailFragment = new DetailFragment(pos);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.detail, detailFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
}
}
});
super.onActivityCreated(savedInstanceState);
}
}
Now here is my image adapter - MyAdapter - for my images which extends a BaseAdapter.
public class MyAdapter extends BaseAdapter {
private Context mContext;
public MyAdapter(Context c) {
mContext = c;
}
#Override
public int getCount() {
return mThumbIds.length;
}
#Override
public Object getItem(int arg0) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(100, 100));
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(0, 0, 0, 0);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
static Integer[] mThumbIds = { R.drawable.pic1, R.drawable.pic2,
R.drawable.pic3, R.drawable.pic4, R.drawable.pic5, R.drawable.pic6,
R.drawable.pic7, R.drawable.pic8, R.drawable.pic9,
R.drawable.pic10, R.drawable.pic11, R.drawable.pic12,
R.drawable.pic13,
};
}
Now I am sharing the XML files for these fragments.
Main.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="horizontal">
<fragment
android:id="#+id/master"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="org.fragment.MasterGridActivity" />
</LinearLayout>
gridview.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="vertical" >
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridViewImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth" />
</LinearLayout>
detail_fragment.xml: This XML is for showing the detail in another fragment.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="8dp" />
</LinearLayout>
</ScrollView>
detail_act.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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
Make the same XML for landscape mode and for tablets. It's working fine for me. Hope it will helpful for you.
You need to define an event callback to the activity activity callback. That is, your left fragment must first notify the container activity that an event occurred (i.e. one of the list items were selected). The container activity will then pass this information to the right fragment, which will then update its UI accordingly.
I could explain this in more detail, but there are several tutorials on the internet that teach just that. I suggest you read through some of them, as the concept will make a lot more sense once you do.

Resources