I am trying to implement shared transition in my app. I want to ImageView in RecyclerView that will be present in next fragment, to have shared transtion from RecyclerView to fragment. But it isn't working. Here is how i did it.
Recycler's item layout
<?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="wrap_content">
<ImageView
android:id="#+id/iv_cover"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:transitionName="cover"
android:src="#drawable/ic_check_circle" />
<View
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#30000000" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/tv_title"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorPrimary"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="BBC"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Caption"
android:textColor="#fff"
android:textSize="16dp" />
<TextView
android:id="#id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorPrimary"
android:maxLines="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="NEWS TITLE"
android:textAppearance="#style/TextAppearance.AppCompat.Caption"
android:textColor="#fff"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Fragment layout
<?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/iv_cover"
android:transitionName="cover"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tv_description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn_story"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Read Full Story"
android:layout_gravity="center"/>
</LinearLayout>
Here is the java code that i used
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//ImageView ivCover = (ImageView) getActivity().findViewById(R.id.iv_cover);
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, feedFragment, "Feed")
.addSharedElement(cover, "cover")
.addToBackStack("Feed")
.commit();
}
Here is the Fragment Code
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
postponeEnterTransition();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setSharedElementEnterTransition(TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move));
}
}
private void loadData() {
String title = null;
String description = null;
String urlToImage = null;
String url = null;
try {
title = getArguments().getString(ARG_PARAM1);
description = getArguments().getString(ARG_PARAM2);
url = getArguments().getString(ARG_PARAM3);
urlToImage = getArguments().getString(ARG_PARAM4);
} catch (Exception e) {
e.printStackTrace();
}
if (title != null)
tvTitle.setText(title);
if (tvDescription != null)
tvDescription.setText(description);
if (urlToImage != null)
Picasso.with(getActivity()).load(urlToImage).into(ivCover, new Callback() {
#Override
public void onSuccess() {
startPostponedEnterTransition();
}
#Override
public void onError() {
startPostponedEnterTransition();
}
});
}
Here is the style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowContentTransitions">true</item>
</style>
What am i doing wrong? Please guide me here. Thanks
In your onBindViewHolder, add the following line:
holder.ivCover.setTransitionName("trans_image" + position);
Each Shared element should have a unique transition name.
So instead of .addSharedElement(cover, "cover") ,
write .addSharedElement(cover, imageTransitionName)
where,
imageTransitionName = rv_imageView.getTransitionName();
and, depending on your implementation (onClickListener will need view.findViewById() instead of getActivity(). ..) ,
ImageView rv_imageView =(ImageView) getActivity().findViewById(R.id.iv_cover);
Also you can also try fade or slide_right or your own custom transition.
All of this will work in the scenario when you click an item and a new detailed fragment appears
So you need to send imageTransitionName in a bundle...and get that argument in details (say) fragment,like
String imageTransitionName = bundle.getString("TRANS_NAME");
view.findViewById(R.id.iv_cover).setTransitionName(imageTransitionName);
Related
I have ControllerFragment which has 3 child fragments. Children fragments change are provided in the tabLayout via ViewPager. Unsend Apple and Banana badge count are computable variable values. unSendAppleCountTxtView and unSendBananaCountTxtView are changed according to these variable values.
My function is running main Thread.
Tried methods:
I have controlled null check and textView isn't null
setUnSendAppleCount function is taken in these threads (runOnUIThread, new Handler(), new Handler(Looper.getMainLooper()))
I have tried AsyncTask and not working setView and setText in postExecute too.
And finally I scan all related questions and tried.
All methods didn't work. TextView is empty value.
public class ControllerFragment extends Fragment {
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.controller_fragment, viewGroup, false);
tabs = ViewUtil.findById(rootView, R.id.tabs);
viewPager = ViewUtil.findById(rootView, R.id.controllerViewPager);
setFragments();
setupViewPager(viewPager);
tabs.setupWithViewPager(viewPager);
setupTabIcons(viewGroup);
return rootView;
}
private void setupTabIcons(ViewGroup viewGroup) {
LinearLayout appleListTab = (LinearLayout) LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.tab_title_text_and_badge, viewGroup, false);
RelativeLayout pearListTab = (RelativeLayout) LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.tab_title_text, viewGroup, false);
LinearLayout bananaListTab = (LinearLayout) LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.tab_title_text_and_badge, viewGroup, false);
unSendAppleCountTxtView = appleListTab.findViewById(R.id.badgeView);
unSendBananaCountTxtView = bananaListTab.findViewById(R.id.badgeView);
TextView appleTextView = appleListTab.findViewById(R.id.textView);
TextView pearTextView = pearListTab.findViewById(R.id.textView);
TextView bananaTextView = bananaListTab.findViewById(R.id.textView);
setUnSendAppleCount(2); //....this function is not working
setUnSendBananaCount(2); //.....this function is not working
bananaTextView.setText(getString(R.string.bananas));
tabs.getTabAt(0).setCustomView(bananaListTab);
appleTextView.setText(getString(R.string.apples));
tabs.getTabAt(1).setCustomView(appleListTab);
pearTextView.setText(getString(R.string.pears));
tabs.getTabAt(2).setCustomView(pearListTab);
}
private void setupViewPager(ViewPager viewPager) {
TabsViewPagerAdapter adapter = new TabsViewPagerAdapter(getFragmentManager());
adapter.addFrag(bananaFragment, getString(R.string.bananas));
adapter.addFrag(appleFragment, getString(R.string.apples));
adapter.addFrag(pearFragment, getString(R.string.pears));
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(1);
}
private void setUnSendAppleCount(int unSendCount) {
if (unSendAppleCountTxtView != null) {
if (unSendCount > 0) {
unSendAppleCountTxtView.setVisibility(View.VISIBLE);
unSendAppleCountTxtView.setText(String.format(getMyLocale(), "%d", unSendCount));
} else {
unSendAppleCountTxtView.setVisibility(View.GONE);
}
}
}
}
controller_fragment xml:
<?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"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/tab_unpressed_color">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/tabColor" />
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/controllerViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/app_bar_layout" />
</RelativeLayout>
tab_title_text_and_badge.xml
<?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:layout_gravity="center"
android:gravity="center"
android:weightSum="2"
android:orientation="horizontal"
tools:background="#color/Black">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:layout_gravity="center"
android:maxLines="1"
android:layout_weight="1.99"
android:textColor="#color/white"
android:textSize="#dimen/infoTitle"/>
<TextView
android:id="#+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="#drawable/tab_controller_badge"
android:gravity="center"
android:textColor="#color/white"
android:textSize="#dimen/miniTextSize"
android:visibility="gone"
tools:text="11"
tools:visibility="visible" />
</LinearLayout>
Please help me
try to setVisibility android:visibility="visible" or android:visibility="invisible" delete gone attribute it remove TextView.
<TextView
android:id="#+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="#drawable/tab_controller_badge"
android:gravity="center"
android:textColor="#color/white"
android:textSize="#dimen/miniTextSize"
android:visibility="visible" //change here
tools:text="11"
tools:visibility="visible" />
Please use android:text instead tools:text
tools:text="text" is used only for Android Studio layout preview (wont be visible while running the app)
android:text="text" is used to set text to a a layout element, which you can see when the app is run
Try using the below xml,
<?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:layout_gravity="center"
android:gravity="center"
android:weightSum="2"
android:orientation="horizontal"
android:background="#color/Black">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:layout_gravity="center"
android:maxLines="1"
android:layout_weight="1.99"
android:textColor="#color/white"
android:textSize="#dimen/infoTitle"/>
<TextView
android:id="#+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="#drawable/tab_controller_badge"
android:gravity="center"
android:textColor="#color/white"
android:textSize="#dimen/miniTextSize"
android:text="11"/>
</LinearLayout>
Hope it helps!
I guess different thread problem. I have tried that eventBus for activity passing data to fragment and it solved.
ControllerFragment(){
#Override
public void onStart() {
super.onStart();
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().register(this);
}
#Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
#Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMain(ControllerEvent event) {
if (event.getSelectedEventType() == ControllerEvent.tabControllerEventTypes.refreshCount.ordinal()) {
setUnSendAppleCount(event.getAppleCount());
}
}
}
I am facing a problem with the position of the error indicator of my EditText when calling editText.setError("...").
As you can see in the screenshot I am using a BottomSheetDialog with an EditText inside of it. When I display the error indicator, the text is completely out of place. It seems as if the dialog "thinks" that it is full-screen, while it is actually not.
This is my dialog layout file (phone_dialog.xml):
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="vertical">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:padding="#dimen/padding_layout_normal"
android:text="#string/dialog_title_edit_phone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<EditText
android:id="#+id/etPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:inputType="phone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvTitle"/>
<Button
android:id="#+id/btnSavePhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etPhone"/>
</android.support.constraint.ConstraintLayout>
My Activity layout file (activity_contacts.xml):
<?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.support.v7.widget.RecyclerView
android:id="#+id/rvContacts"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
This is how I show the dialog from my Activity:
PhoneBottomDialog dialog = new PhoneBottomDialog(Context);
dialog.show();
This is my PhoneBottomDialog class:
public class PhoneBottomDialog extends BottomSheetDialog {
public PhoneBottomDialog(Context context) {
super(context);
View view = getLayoutInflater().inflate(R.layout.phone_dialog, null);
setContentView(view);
// additional setup below this...
}
// ...
}
I am not performing any other layouting inside my custom PhoneButtomDialog. Changing the root layout of my dialog to RelativeLayout or LinearLayout as well as adding a ScrollView did not change anything. It's also not a device or specific Android version related issue as the problem occurs on all of my testing devices ranging from Android 5.0 to 7.1, it also occurs on the emulator.
Does anyone have an idea why this is happening?
You can use TextInputLayout and inside that you can define Edit Text.
I have done some modification inside your phone_dialog.xml.
phone_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="bottom"
android:background="#android:color/holo_blue_light"
android:padding="10dp"
app:behavior_hideable="true"
app:behavior_peekHeight="60dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:gravity="center"
android:padding="10dp"
android:text="dialog_title_edit_phone" />
<android.support.design.widget.TextInputLayout
android:id="#+id/inputPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextInputLayoutLabel">
<EditText
android:id="#+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone"
android:imeOptions="actionDone"
android:inputType="phone"
android:maxLines="1"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/btnSavePhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etPhone"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="8dp"
android:text="Save" />
</LinearLayout>
</FrameLayout>
Inside style.xml add this.
<style name="TextInputLayoutLabel" parent="Widget.Design.TextInputLayout">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#android:color/black</item>
<item name="android:textSize">15sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/colorPrimary</item>
<item name="colorControlNormal">#color/colorAccent</item>
<item name="colorControlActivated">#color/colorAccent</item>
</style>
PhoneBottomDialog.java
public class PhoneBottomDialog extends BottomSheetDialog {
TextInputLayout inputPhone;
EditText edtPhone;
Button btnSave;
public PhoneBottomDialog(Context context) {
super(context);
View view = getLayoutInflater().inflate(R.layout.phone_dialog, null);
setContentView(view);
// additional setup below this...
inputPhone = (TextInputLayout) view.findViewById(R.id.inputPhone);
edtPhone = (EditText) view.findViewById(R.id.etPhone);
btnSave = (Button) view.findViewById(R.id.btnSavePhone);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!validatePhone())
return;
}
});
}
private boolean validatePhone() {
if (edtPhone.getText().toString().isEmpty()) {
inputPhone.setError("Please enter valid phone number with country code.");
requestFocus(edtPhone);
return false;
} else {
inputPhone.setErrorEnabled(false);
}
return true;
}
private void requestFocus(View view) {
if (view.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
// ...
}
And inside Activity.
#SuppressLint("SetTextI18n")
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test24);
mContext = this;
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
PhoneBottomDialog dialog = new PhoneBottomDialog(mContext);
dialog.show();
}
Below you can see the output for this.
add compile 'com.android.support:design:24.2.0' in gradle dependencies
use TextInputLayout in xml.
<android.support.design.widget.TextInputLayout
android:id="#+id/textInputServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="36dp"
app:errorTextAppearance="#style/TextErrorAppearance">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
........./>
</android.support.design.widget.TextInputLayout>
From Lollipop(5.0) version android provide TextInputLayout to do this.
Use below xml and java code to show same type view.
abc.xml:
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
app:theme="#style/AppTheme">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true"
android:textColor="#color/icons"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
Abc.java:
private TextInputLayout
textInputLayout_User = (TextInputLayout) findViewById(R.id.text_input_layout_user);
textInputLayout_User.setError(getString(R.string.valid_username));
Note : This is popup menu not popup window.So I request you all to read carefully.
I have implemented pop menu. It is displaying in half of the screen. I want to spread this to entire width of device. I tried to change its style by setting layout_width as match_parent but with no success.
Below is what I tried so far:
Style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="popupMenuStyle">#style/PopupMenu</item>
</style>
<!-- Change Overflow Menu Background -->
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#888888</item>
<item name="android:layout_width">match_parent</item>
</style>
Below is my java code:
PopupMenu menu = new PopupMenu(getActivity(), tvnext);
for (int i = 0; i < array.size(); i++) {
menu.getMenu().add(1, i, 1, array.get(i).getAccountName());
}
menu.show();
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
setUpNextFunctionality(item.getItemId());
return false;
}
});
P.S : Please don't suggest me to use popup window. This is my last option if nothing work.
I got your question. Instead of modify something use new widget which can easily fulfill your necessary and compatible with newer version.
Google introduce new Material concept as Bottom-Sheet
To use it in android you can use git hub libraries like this.
I don't think you can do that without implementing of your own popup window similar to PopupMenu. If you will check MenuPopupHelper::createPopup:
#NonNull
private MenuPopup createPopup() {
final WindowManager windowManager = (WindowManager) mContext.getSystemService(
Context.WINDOW_SERVICE);
final Display display = windowManager.getDefaultDisplay();
final Point displaySize = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(displaySize);
} else if (Build.VERSION.SDK_INT >= 13) {
display.getSize(displaySize);
} else {
displaySize.set(display.getWidth(), display.getHeight());
}
final int smallestWidth = Math.min(displaySize.x, displaySize.y);
final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize(
R.dimen.abc_cascading_menus_min_smallest_width);
final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading;
final MenuPopup popup;
if (enableCascadingSubmenus) {
popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr,
mPopupStyleRes, mOverflowOnly);
} else {
popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr,
mPopupStyleRes, mOverflowOnly);
}
// Assign immutable properties.
popup.addMenu(mMenu);
popup.setOnDismissListener(mInternalOnDismissListener);
// Assign mutable properties. These may be reassigned later.
popup.setAnchorView(mAnchorView);
popup.setCallback(mPresenterCallback);
popup.setForceShowIcon(mForceShowIcon);
popup.setGravity(mDropDownGravity);
return popup;
}
you will see that size of PopupMenu kind of hardcoded as per display size. So probably easy way is to check PopupMenu related source code and implement something similar, but with sizes which you'd like to have.
Trythis:
pwindow =
new PopupWindow(layoutt,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,true);
Try to set minWidth in your style as below
<item name="android:minWidth">1000dp</item>
try this ,
inflater.inflate(R.layout.menu, menu);
or
menu.inflate(R.layout.popup_menu);
Make it translucent. I made same for pop up like this. Please check this one. May be it also work for you.
In your manifest:
<activity
android:name=".ActivityInviteFriend"
android:theme="#style/Theme.TransparentInfo">
</activity>
In style: main theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/LightappActionBarColor</item>
<item name="colorPrimaryDark">#color/appColor</item>
<item name="colorAccent">#color/btn_color</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
and your custom theme:
<color name="semiTransparentBlack">#00000000</color>
<style name="Theme.TransparentInfo" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#color/semiTransparentBlack</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Your Activity:
package com.gc.naifizzy;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class ActivityInviteFriend extends AppCompatActivity {
Button btn_send;
Snackbar snackbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
setContentView(R.layout.activity_invite_friend);
btn_send = (Button) findViewById(R.id.btn_send);
btn_send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//snack("Invitation sent successfully...");
Toast.makeText(ActivityInviteFriend.this, "Invitation sent successfully", Toast.LENGTH_SHORT).show();
finish();
}
});
}
public void snack(String data) {
snackbar = Snackbar
.make(findViewById(android.R.id.content), data, Snackbar.LENGTH_LONG)
.setAction("Dismiss", new View.OnClickListener() {
#Override
public void onClick(View view) {
snackbar.dismiss();
}
});
snackbar.show();
}
}
and finally your xml layout :
<?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:background="#502f2f2f">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:background="#android:color/white"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<RelativeLayout
android:id="#+id/dds"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#112f2f2f"
android:paddingTop="10dp"
android:visibility="visible">
<TextView
android:id="#+id/txt_what"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical|left"
android:paddingLeft="10dp"
android:text="Invite people to join your tree on Naifizzy"
android:textColor="#color/appColor"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="#id/dds"
android:layout_marginTop="3dp"
android:alpha="0.5"
android:background="#color/appColor"
android:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/view"
android:layout_marginTop="20dp"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">
<TextView
android:id="#+id/txt_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Invite people by sharing this link "
android:textColor="#992f2f2f"
android:textSize="15sp" />
<EditText
android:id="#+id/edt_user_link"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#id/txt_share"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/layout_border"
android:editable="false"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="http://naifizzy.com/#parik_dhakan"
android:textColor="#992f2f2f"
android:textSize="15sp" />
<View
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/edt_user_link"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:alpha="0.5"
android:background="#color/appColor" />
<TextView
android:id="#+id/txt_share2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/view1"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Send by email "
android:textColor="#992f2f2f"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1">
<LinearLayout
android:id="#+id/ed_l"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:background="#drawable/layout_border"
android:orientation="horizontal"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:id="#+id/edl_current"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:paddingTop="5dp"
android:textColorHint="#992f2f2f"
android:textSize="15sp">
<EditText
android:id="#+id/edt_mail"
style="#style/StyledTilEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:hint="Enter recipients' Email seprated by commas "
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
android:textColor="#992f2f2f"
android:textColorHint="#992f2f2f"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="#+id/img_show"
android:layout_width="30dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:scaleType="centerInside"
android:src="#drawable/ic_eye"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
<EditText
android:id="#+id/edt_user_link2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/txt_share2"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/layout_border"
android:paddingLeft="10dp"
android:singleLine="true"
android:text="http://naifizzy.com/#parik_dhakan"
android:textColor="#992f2f2f"
android:textSize="15sp"
android:visibility="gone" />
<Button
android:id="#+id/btn_send"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
android:layout_weight="0.8"
android:background="#drawable/signupbg"
android:gravity="center_vertical|center_horizontal"
android:text="Send\nInvites"
android:textColor="#android:color/white"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
I am using Vuforia AR sdk and want to create a button on the camera preview on the screen.
I cannot figure out where and how to add the button.
I have edit the camera_overlay_udt.xml like this.. In my layout design i have placed back button and listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:src="#drawable/back" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Swipart"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/arcstarButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:src="#drawable/star_button" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/favListingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ListView
android:id="#+id/favlist"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="7dp"
android:cacheColorHint="#00000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#color/overlay_bottom_bar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1" >
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/overlay_bottom_bar_separators" />
<ImageButton
android:id="#+id/camera_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:contentDescription="#string/content_desc_camera_button"
android:onClick="onCameraClick"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/camera_button_background" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/bottom_bar"
android:background="#color/overlay_bottom_bar_separators" />
</RelativeLayout>
after that please Edit that ImageTargets.java class
private void addOverlayView(boolean initLayout) {
// Inflates the Overlay Layout to be displayed above the Camera View
LayoutInflater inflater = LayoutInflater.from(this);
mUILayouts = (RelativeLayout) inflater.inflate(
R.layout.camera_overlay_udt, null, false);
mUILayouts.setVisibility(View.VISIBLE);
// If this is the first time that the application runs then the
// uiLayout background is set to BLACK color, will be set to
// transparent once the SDK is initialized and camera ready to draw
if (initLayout) {
mUILayouts.setBackgroundColor(Color.TRANSPARENT);
}
// Adds the inflated layout to the view
addContentView(mUILayouts, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Gets a reference to the bottom navigation bar
mBottomBar = mUILayouts.findViewById(R.id.bottom_bar);
// Gets a reference to the Camera button
mCameraButton = mUILayouts.findViewById(R.id.camera_button);
mCameraButton.setVisibility(View.GONE);
favButton = (ImageButton) mUILayouts.findViewById(R.id.arcstarButton);
listview = (ListView) mUILayouts.findViewById(R.id.favlist);
backButton = (ImageButton) mUILayouts.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
finish();
}
});
listview.setVisibility(View.GONE);
galleryList = SendFile.getFavourites();
if (galleryList != null) {
gridviewAdapter = new GridviewAdapter(ImageTargets.this);
listview.setAdapter(gridviewAdapter);
}
favButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (galleryList != null && galleryList.size() > 0) {
if (listview.getVisibility() == View.GONE) {
listview.setVisibility(View.VISIBLE);
} else {
listview.setVisibility(View.GONE);
}
} else {
Toast.makeText(ImageTargets.this, "Favourites not fond",
Toast.LENGTH_LONG).show();
}
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paramAdapterView,
View paramView, int positon, long paramLong) {
SendFile.setFavourite(galleryList.get(positon));
Intent intent = new Intent(ImageTargets.this,
LoadingScreen.class);
Bundle bundle = new Bundle();
bundle.putInt("x", x_Axis);
bundle.putInt("y", y_Axis);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
showDialogHandler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Server Response: " + aResponse, Toast.LENGTH_SHORT)
.show();
showAlertDialog(aResponse);
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Not Got Response From Server.", Toast.LENGTH_SHORT)
.show();
}
};
};
loadingDialogHandler.captureButtonContainer = mUILayouts
.findViewById(R.id.camera_button);
mUILayouts.bringToFront();
}
They showing there layouts using handlers
Start you camera preview in a normal way. Place a layout on top of it with transparent background like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ff000000"
android:layout_height="match_parent">
<ImageView
android:id="#+id/start_image_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:src="#drawable/scan_image"/>
</RelativeLayout>
In java file, you can add this layout like this:
private View mStartupView;
mStartupView = getLayoutInflater().inflate(
R.layout.startup_screen, null);
// Add it to the content view:
addContentView(mStartupView, new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
This way you will get to see your button on top of camera preview. Hope it helps
You can add buttons in cameraoverlay layout which is in layout folder and you can initialize buttons in initAR function which is in mainactivity.
Step 1: Add the button in the camera_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
style="#android:style/Widget.ProgressBar"
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="51dp"
android:text="Button" />
</RelativeLayout>
Step 2: Edit the ImageTargets.java class
private static final String LOGTAG = "ImageTargets";
private Button b1;
Step 3: Modify the initApplicationAR() function of ImageTargets.java class
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
b1.setVisibility(View.GONE);
}
});
}
Now lay back and watch your button disappear on a click!
Although it's a long time since the post.. yet I found one article.. wherein you can have the desired thing..
Ref: https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82
Solution:
Step1: Make a custom layout XML file (vuforia_widget_screen.xml). For example, button has been added.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:text="#string/welcome" />
</FrameLayout>
Step 2: Make following changes in the UnityPlayerActivity.java
Replace "setContentView(mUnityPlayer);" with
setContentView(R.layout.vuforia_widget_screen);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
-> For anyone, who will face the issue in future. :)
New android developer here. I am trying to create a dynamic UI that loads based on the users selection of a RadioGroup. Based on their selection, one of 3 possible fragments will be loaded into a LinearLayout section. This is my first attempt at my own sample problem that is not just a walk-through tutorial. Here is the main activity:
public class BaseConverter extends Activity {
RadioGroup convert;
Fragment toFragment;
RadioGroup toRadioGroup = null;
TextView inputDisplay = null;
TextView outputDisplay = null;
TextView resultTitle = null;
#Override
public void onCreate(Bundle sIS) {
super.onCreate(sIS);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.base_converter);
convert = (RadioGroup) this.findViewById(R.id.bc_convert_group);
convert.setOnCheckedChangeListener(new ConvertListener());
FragmentManager fm = getFragmentManager();
FragmentTransaction converterFragment = fm.beginTransaction();
ConvertEmptyFragment emptyTo = new ConvertEmptyFragment();
converterFragment.replace(R.id.bc_converter_fragment, emptyTo);
converterFragment.commit();
FragmentTransaction toFragment = fm.beginTransaction();
ConvertEmptyFragment emptyConverter = new ConvertEmptyFragment();
toFragment.replace(R.id.bc_to_fragment, emptyConverter);
toFragment.commit();
}
#Override
public void onResume() {
convert.clearCheck();
super.onResume();
}
#Override
public void onPause() {
convert.clearCheck();
super.onPause();
}
// I put a little null check so you can see how I'm trying to access the TextViews and what results
public void updateUIComponents(){
View converterView = this.findViewById(R.id.bc_converter_fragment);
inputDisplay = (TextView)converterView.findViewById(R.id.bc_display_input);
outputDisplay = (TextView)converterView.findViewById(R.id.bc_display_output);
if (inputDisplay == null){
Log.d("BaseConverter", "inputDisplay == null");
} else {
Log.d("BaseConverter", "inputDisplay != null");
}
}
class ConvertListener implements OnCheckedChangeListener {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Fragment toFragment;
Fragment converterFragment;
switch (checkedId) {
case R.id.bc_convert_binary:
toFragment = new ConvertRBFragmentBinary();
converterFragment = new ConverterFragmentBinary();
break;
case R.id.bc_convert_decimal:
toFragment = new ConvertRBFragmentDecimal();
converterFragment = new ConverterFragmentDecimal();
break;
case R.id.bc_convert_hex:
toFragment = new ConvertRBFragmentHex();
converterFragment = new ConverterFragmentHex();
break;
default:
toFragment = new ConvertEmptyFragment();
converterFragment = new ConvertEmptyFragment();
break;
}
FragmentManager fm = getFragmentManager();
FragmentTransaction converterTransaction = fm.beginTransaction();
converterTransaction.replace(R.id.bc_converter_fragment, converterFragment);
converterTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
converterTransaction.commit();
FragmentTransaction toTransaction = fm.beginTransaction();
toTransaction.replace(R.id.bc_to_fragment, toFragment);
toTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
toTransaction.commit();
updateUIComponents();
}
}
So, based on what a user chooses, the proper fragments will be loaded into the respective LinearLayout sections. However, now I want to implement the business logic of the fragments (which is just integer base conversion; i.e. binary number to decimal...) but when I try to access the TextViews, as seen in the updateUIComponents method, I get null pointers. What am I missing?
Here's the ConverterFragmentBinary class for reference:
public class ConverterFragmentBinary extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sIS){
View v = inflater.inflate(R.layout.converter_fragment_binary, container, false);
return v;
}
}
and its respective xml layout for reference:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF000000"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/bc_binary_converter_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip"
android:maxHeight="30dip"
android:src="#drawable/binary_converter" />
<TextView
android:id="#+id/bc_display_input"
style="#style/input_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:layout_marginTop="5dip"
android:gravity="center_vertical|right"
android:lines="1"
android:minHeight="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF000000"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="#+id/button_num_0"
style="#style/op_button_land"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="center"
android:onClick="num0"
android:text="#string/num_0" />
<Button
android:id="#+id/button_num_1"
style="#style/op_button_land"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="center"
android:onClick="num1"
android:text="#string/num_1" />
</LinearLayout>
<TextView
android:id="#+id/bc_result_title"
style="#style/radio_button_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:gravity="left"
android:text="#string/choose_convert" />
<TextView
android:id="#+id/bc_display_output"
style="#style/display_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:layout_marginTop="5dip"
android:gravity="center_vertical|right"
android:lines="1"
android:minHeight="30sp" />
</LinearLayout>
and then heres the main activity it gets loaded into:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/base_conversion_layout"
style="#style/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="5"
android:baselineAligned="false"
android:gravity="center_vertical|left"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
style="#style/radio_button_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/convert" />
<RadioGroup
android:id="#+id/bc_convert_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dip" >
<RadioButton
android:id="#+id/bc_convert_binary"
style="#style/radio_button"
android:text="#string/binary" />
<RadioButton
android:id="#+id/bc_convert_decimal"
style="#style/radio_button"
android:text="#string/decimal" />
<RadioButton
android:id="#+id/bc_convert_hex"
style="#style/radio_button"
android:text="#string/hex" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:id="#+id/bc_to_fragment"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bc_converter_fragment"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="13"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Thanks in advance and sorry for the long code blocks but I figured it was better to include more than less.
Also, you should inflate your Fragments layout to bring it from your XML to your Java code instead of simply referring it using findViewById() method.
So instead of doing this,
View converterView = this.findViewById(R.id.bc_converter_fragment);
Do this inside your onCreateView method of the fragment,
View converterView = infalter.inflate(R.id.bc_converter_fragment,null);
updateUIComponents(converterView);//call this methid and pass your view
new method looks like this,
public void updateUIComponents(View converterView){
inputDisplay = (TextView)converterView.findViewById(R.id.bc_display_input);
outputDisplay = (TextView)converterView.findViewById(R.id.bc_display_output);
if (inputDisplay == null){
Log.d("BaseConverter", "inputDisplay == null");
} else {
Log.d("BaseConverter", "inputDisplay != null");
}
}