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());
}
}
}
Related
Here is my code.i want to put 3 recyclerViews in my layout but it is very slow on device while running. If there is 2 recyclerview it works smooth but if 3 slow very :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/scroll_view"
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="wrap_content"
tools:context=".fragments.MainFragment">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#color/blacker"
android:textStyle="bold"
android:textSize="18sp"
android:text="Техника для офиса"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp" />
<android.support.v7.widget.RecyclerView
android:nestedScrollingEnabled="false"
android:fillViewport="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:id="#+id/recyclerView_popular_goods"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<TextView
android:textColor="#color/blacker"
android:textStyle="bold"
android:textSize="18sp"
android:text="Компьютерная техника"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp" />
<android.support.v7.widget.RecyclerView
android:nestedScrollingEnabled="false"
android:fillViewport="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:id="#+id/recyclerView_competitive_goods"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<TextView
android:textColor="#color/blacker"
android:textStyle="bold"
android:textSize="18sp"
android:text="Канцелярские товары"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp" />
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:fillViewport="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:id="#+id/recyclerView_stationery_goods"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</LinearLayout>
Please if somebody had such kind of problem please help me to fix my issue.
I tried Nested scrollview and setNestedScrollingEnabled = false.but nothing helps
Here is my Activity
#SuppressLint("ValidFragment")
public class MainFragment extends BasicFragment implements
MainFragmentView, PopularGoodsAdapter.ProductListener {
#BindView(R.id.scroll_view)
NestedScrollView mScrollView;
#BindView(R.id.recyclerView_stationery_goods)
RecyclerView mRecyclerViewStationeryGoods;
#BindView(R.id.recyclerView_popular_goods)
RecyclerView mRecyclerViewPopularGoods;
#BindView(R.id.recyclerView_competitive_goods)
RecyclerView mRecyclerViewCompetitiveGoods;
#BindView(R.id.imageSlider)
SliderView mSliderView;
#Inject
Navigator mNavigator;
#Inject
#Named(DISPLAY_WIDTH)
int mDisplayWidth;
#InjectPresenter
MainFragmentPresenter mPresenter;
List<Product> list1;
List<Product> list2;
List<Product> list3;
private PopularGoodsAdapter mAdapterPopularGoods;
private PopularGoodsAdapter mAdapterPopularGoods2;
private PopularGoodsAdapter mAdapterPopularGoods3;
private LayoutAnimationController layoutAnimationController;
private List<String> images;
#SuppressLint("ValidFragment")
public MainFragment() {
}
private void initView(View view) {
ButterKnife.bind(this,view);
images = new LinkedList<>();
images.add("https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260");
images.add("https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
images.add("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
mSliderView.setSliderAdapter(new SliderAdapterExample(getContext(), images, "mainPage"));
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
LinearLayoutManager layoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
LinearLayoutManager layoutManager3 = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerViewPopularGoods.setLayoutManager(layoutManager);
layoutAnimationController = AnimationUtils.loadLayoutAnimation(getContext(),R.anim.layout_item_from_left);
list1 = new LinkedList<>();
mRecyclerViewPopularGoods.setLayoutAnimation(layoutAnimationController);
mRecyclerViewCompetitiveGoods.setLayoutManager(layoutManager2);
list2 = new LinkedList<>();
mRecyclerViewCompetitiveGoods.setLayoutAnimation(layoutAnimationController);
mRecyclerViewStationeryGoods.setLayoutManager(layoutManager3);
list3 = new LinkedList<>();
mRecyclerViewStationeryGoods.setLayoutAnimation(layoutAnimationController);
mRecyclerViewPopularGoods.setAdapter(mAdapterPopularGoods = new PopularGoodsAdapter(getContext(),list1,mDisplayWidth,"popular",this));
mRecyclerViewCompetitiveGoods.setAdapter(mAdapterPopularGoods2 = new PopularGoodsAdapter(getContext(),list2,mDisplayWidth,"competitive",this));
mRecyclerViewStationeryGoods.setAdapter(mAdapterPopularGoods3 = new PopularGoodsAdapter(getContext(),list3,mDisplayWidth,"stationery",this));
mRecyclerViewPopularGoods.setNestedScrollingEnabled(false);
mRecyclerViewCompetitiveGoods.setNestedScrollingEnabled(false);
mRecyclerViewStationeryGoods.setNestedScrollingEnabled(false);
getLoadingDialog().showDialog(getFragmentManager());
mPresenter.GET_TOP_HOME_VIEW();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup
container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container,
false);
initView(view);
return view;
}
#OnClick({R.id.item_sellers,
R.id.item_price_request,R.id.item_price_competitions})
void Onclick(View view) {
switch (view.getId()) {
case R.id.item_sellers:
mNavigator.toSellersActivty(getContext());
break;
case R.id.item_price_request:
mNavigator.toPriceRequestActivty(getContext());
break;
case R.id.item_price_competitions:
mNavigator.toCompetitionsActivty(getContext());
break;
}
}
#Override
public void initTopHomeView(List<HomeViewObject> result) {
if (null != result ) {
if (result.size() >= 1 && null != result.get(0)) {
list1.addAll(result.get(0).getTopProducts());
mAdapterPopularGoods.notifyDataSetChanged();
mRecyclerViewPopularGoods.setLayoutAnimation(layoutAnimationController);
}
if (result.size() >= 2 && null != result.get(1)) {
list2.addAll(result.get(1).getTopProducts());
mAdapterPopularGoods2.notifyDataSetChanged();
mRecyclerViewPopularGoods.setLayoutAnimation(layoutAnimationController);
}
if (result.size() >= 3 && null != result.get(2)) {
list3.addAll(result.get(2).getTopProducts());
mAdapterPopularGoods3.notifyDataSetChanged();
mRecyclerViewStationeryGoods.setLayoutAnimation(layoutAnimationController);
}
}
}
#Override
public void stopProgress() {
getLoadingDialog().hideDialog();
}
#Override
public void onProductClicked(Product product) {
mNavigator.toProductActivity(getContext(),product);
}
}
Is there any mistake?
Try the following -
Try to put all the views inside NestedScrollView i.e, root view.
Set recyclerView.setNestedScrollingEnabled(false); for both the recyclerViews in your xml.
Change your recycler view's android:layout_height="match_parent" to android:layout_height="wrap_content" and then use Nested scrollView with recyclerView.setNestedScrollingEnabled(false);
try to change your ScrollView with NestedScrollViewand Change your recycler view's android:layout_height="match_parent" to android:layout_height="wrap_content" :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragments.MainFragment">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#color/blacker"
android:textStyle="bold"
android:textSize="18sp"
android:text="Техника для офиса"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp" />
<android.support.v7.widget.RecyclerView
android:nestedScrollingEnabled="false"
android:fillViewport="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:id="#+id/recyclerView_popular_goods"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:textColor="#color/blacker"
android:textStyle="bold"
android:textSize="18sp"
android:text="Компьютерная техника"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp" />
<android.support.v7.widget.RecyclerView
android:nestedScrollingEnabled="false"
android:fillViewport="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:id="#+id/recyclerView_competitive_goods"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:textColor="#color/blacker"
android:textStyle="bold"
android:textSize="18sp"
android:text="Канцелярские товары"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp" />
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:fillViewport="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:id="#+id/recyclerView_stationery_goods"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
and :
RecyclerView recycleView1 = (RecyclerView) findViewById(R.id.recyclerView_popular_goods);
RecyclerView recycleView2 = (RecyclerView) findViewById(R.id.recyclerView_competitive_goods);
RecyclerView recycleView3 = (RecyclerView) findViewById(R.id.recyclerView_stationery_goods);
recycleView1.setNestedScrollingEnabled(false);
recycleView2.setNestedScrollingEnabled(false);
recycleView3.setNestedScrollingEnabled(false);
If your devices API is below v 21, use the following:
ViewCompat.setNestedScrollingEnabled(recycleView1, false);
ViewCompat.setNestedScrollingEnabled(recycleView2, false);
ViewCompat.setNestedScrollingEnabled(recycleView3, false);
Your design needs to change. As soon as you're adding RecyclerView with nested scrolling disabled, you should keep in mind that view will have its items created all at once.
It basically means no typical RecyclerView optimization magic when only needed amount of items is created and rendered, then reused, based on screen real estate etc.
In your case the situation is even less good as you have 3 such RecyclerViews. The performance of your solution will of course depend on hardware and number of items inside each RecyclerView, but pls do consider using just ONE RecyclerView and no ScrollView at all.
Finally I achieved.I used NestedScrollView as root.And used only 1 recyclerview.And in adapter of this recyclerview I created other recyclerViews.Scrolling smooth Thanks #Venky
I have a ScollView Layout with a FrameLayout that includes two different layouts. If some condition is met, I set one or the other as visible.
dialog_interface_login.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:font="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_white"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/landing_login_view"/>
<include layout="#layout/mobile_login_view"/>
</FrameLayout>
</ScrollView>
My class:
final View v = inflater.inflate(R.layout.dialog_interface_login, container, false);
View mobileLayout = v.findViewById(R.id.mobile_root_view);
View landingLayout = v.findViewById(R.id.landing_root_view);
if (landingLogin) {
mobileLayout.setVisibility(View.INVISIBLE);
landingLayout.setVisibility(View.VISIBLE);
} else {
mobileLayout.setVisibility(View.VISIBLE);
landingLayout.setVisibility(View.INVISIBLE);
}
Inside theese layouts that was set on the include, I have another include:
landing_login_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:font="http://schemas.android.com/apk/res-auto"
android:id="#+id/landing_root_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_white"
android:paddingLeft="#dimen/twenty_eight_dp"
android:paddingRight="#dimen/twenty_eight_dp"
android:orientation="vertical">
...
<include layout="#layout/sms_login"/>
...
</LinearLayout>
And mobile_login_view.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:font="http://schemas.android.com/apk/res-auto"
android:id="#+id/mobile_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/color_white"
android:paddingLeft="#dimen/twenty_eight_dp"
android:paddingRight="#dimen/twenty_eight_dp"
android:orientation="vertical">
...
<include layout="#layout/sms_login"/>
</LinearLayout>
This is my sms_login.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:font="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_white"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="#dimen/fifty_six_dp"
android:layout_marginBottom="#dimen/twelve_dp"
android:background="#drawable/btn_white_enabled">
<br.com.fs.fslogin.ui.support.views.GothamEditText
android:id="#+id/et_phone_number"
style="#style/AppTheme.RectangularEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:digits="0123456789"
android:gravity="center"
android:hint="#string/hint_enter_phone"
android:inputType="number|none"
android:maxLength="11"
android:textColorHint="#color/task_done_color"
android:textSize="#dimen/sixteen_sp"
font:name="#string/font_gotham_medium" />
</FrameLayout>
<FrameLayout
android:id="#+id/dialog_error_phone"
android:layout_width="match_parent"
android:layout_height="#dimen/thirty_two_dp"
android:layout_marginBottom="#dimen/twelve_dp"
android:background="#drawable/bg_warning_phone"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/eight_dp"
android:layout_marginStart="#dimen/eight_dp"
android:contentDescription="#null"
android:src="#drawable/ic_error_phone_red" />
<br.com.fs.fslogin.ui.support.views.GothamTextView
android:id="#+id/error_phone_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:lineSpacingExtra="#dimen/two_sp"
android:textColor="#color/error_login_phone_color"
android:textSize="#dimen/fourteen_sp"
font:name="#string/font_gotham_medium" />
</FrameLayout>
<FrameLayout
android:id="#+id/btn_sms_login"
android:layout_width="match_parent"
android:layout_height="#dimen/fifty_six_dp"
android:background="#drawable/btn_login_vivo_purple">
<br.com.fs.fslogin.ui.support.views.GothamButton
style="#style/AppTheme.RectangularButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#null"
android:clickable="false"
android:gravity="center"
android:text="#string/btn_login"
android:textColor="#android:color/white"
android:textSize="#dimen/eighteen_sp"
font:name="#string/font_gotham_bold" />
</FrameLayout>
</LinearLayout>
Programmatically, I set some behaviors, such as a mask for the phone field etc.
But these behaviors that are programmatically configured in sms_login.xml will only occur if the layout is set first in my dialog_interface_login.xml. I have the same include, with the same information, but only works on the first one that is defined at ContainerLayout. Even the onclick event does not trigger.
Do you have any idea why? Is it possible to define two different includes?
----- Edited -----
Including some actions done
v.findViewById(R.id.btn_sms_login).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (phoneWatcher.isPhoneNumberValid()) {
String phoneNumber = etPhoneNumber.getText().toString().replaceAll("\\D+", "");
onSuccessClick.OnSuccess(phoneNumber);
LoginInterfaceVivoSyncDialog.this.dismiss();
}
}
});
You should use Visibility.GONE instead of INVISIBLE
You can directly assign id to include block why you made two extra different layouts to give just an id.
I was shocked to see #dimen/twelve_dp (really shocked). What is use of dimens.xml if you are writing twelve_dp there. You can directly write 12dp. It should be generic like space_small or space_large or text_size_small.
Also removed some extra wrapping layouts from your xml.
dialog_interface_login.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_white"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/landing_root_view"
layout="#layout/sms_login" />
<include
android:id="#+id/mobile_root_view"
layout="#layout/sms_login" />
</FrameLayout>
</ScrollView>
and
final View v = inflater.inflate(R.layout.dialog_interface_login, container, false);
View mobileLayout = v.findViewById(R.id.mobile_root_view);
View landingLayout = v.findViewById(R.id.landing_root_view);
if (landingLogin) {
mobileLayout.setVisibility(View.GONE);
landingLayout.setVisibility(View.VISIBLE);
} else {
mobileLayout.setVisibility(View.VISIBLE);
landingLayout.setVisibility(View.GONE);
}
sms_login.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:font="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/color_white"
android:orientation="vertical">
<br.com.fs.fslogin.ui.support.views.GothamEditText
android:id="#+id/et_phone_number"
style="#style/AppTheme.RectangularEditText"
android:layout_width="match_parent"
android:layout_height="#dimen/fifty_six_dp"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/twelve_dp"
android:background="#drawable/btn_white_enabled"
android:digits="0123456789"
android:gravity="center"
android:hint="#string/hint_enter_phone"
android:inputType="number|none"
android:maxLength="11"
android:textColorHint="#color/task_done_color"
android:textSize="#dimen/sixteen_sp"
font:name="#string/font_gotham_medium" />
<FrameLayout
android:id="#+id/dialog_error_phone"
android:layout_width="match_parent"
android:layout_height="#dimen/thirty_two_dp"
android:layout_marginBottom="#dimen/twelve_dp"
android:background="#drawable/bg_warning_phone"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/eight_dp"
android:layout_marginStart="#dimen/eight_dp"
android:contentDescription="#null"
android:src="#drawable/ic_error_phone_red" />
<br.com.fs.fslogin.ui.support.views.GothamTextView
android:id="#+id/error_phone_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:lineSpacingExtra="#dimen/two_sp"
android:textColor="#color/error_login_phone_color"
android:textSize="#dimen/fourteen_sp"
font:name="#string/font_gotham_medium" />
</FrameLayout>
<br.com.fs.fslogin.ui.support.views.GothamButton
android:id="#+id/btn_sms_login"
style="#style/AppTheme.RectangularButton"
android:layout_width="wrap_content"
android:layout_height="#dimen/fifty_six_dp"
android:layout_gravity="center"
android:background="#drawable/btn_login_vivo_purple"
android:clickable="false"
android:gravity="center"
android:text="#string/btn_login"
android:textColor="#android:color/white"
android:textSize="#dimen/eighteen_sp"
font:name="#string/font_gotham_bold" />
</LinearLayout>
Do you have any idea why?
This happens because findViewById(R.id.xyz) returns the first View which has the requested attribute android:id="#+id/R.id.xyz".
Quoting from the documentation on View:
Finds the first descendant view with the given ID, the view itself if the ID matches getId(), or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.
To access the correct View, you'll have to use some property which makes it unique. In your case, for example the value R.id.et_phone_number can be found twice in the FrameLayout. But if you write
View myView = mobileLayout.findViewById(R.id.et_phone_number);
then there will be just one child View of mobileLayout with the requested id.
Your code snippet can be changed as follows:
final View v = inflater.inflate(R.layout.dialog_interface_login, container, false);
View mobileLayout = v.findViewById(R.id.mobile_root_view);
View landingLayout = v.findViewById(R.id.landing_root_view);
if (landingLogin) {
mobileLayout.setVisibility(View.INVISIBLE);
landingLayout.setVisibility(View.VISIBLE);
} else {
mobileLayout.setVisibility(View.VISIBLE);
landingLayout.setVisibility(View.INVISIBLE);
}
setupViewGroup(mobileLayout);
setupViewGroup(landingLayout);
The method setupViewGroup(View layout) should look like this:
private void setupViewGroup(View layout)
{
final EditText etPhoneNumber = layout.findViewById(R.id.et_phone_number);
layout.findViewById(R.id.btn_sms_login).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (phoneWatcher.isPhoneNumberValid()) {
String phoneNumber = etPhoneNumber.getText().toString().replaceAll("\\D+", "");
// ...
}
}
});
}
By calling findViewById() on layout you will get the desired child Views of the ViewGroups which were added by using <include .../>
I have dialogs in other places in the app that work just fine(keyboad doesn't hide the view) , but in this particular new dialog I wrote it doesn't move the view up when the keyboard is on. I can't figure out why..
My dialog's layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="#+id/MyLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:background="#drawable/dialog_background"
android:clickable="true"
android:orientation="vertical"
custom:maxHeight="#dimen/dialog_max_height"
custom:maxWidth="#dimen/dialog_max_width" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="something" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<EditText
android:id="#+id/SomeEditText"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:minHeight="100dp"
android:layout_margin="15dp"
android:background="#ffffff"
android:gravity="right|top"
android:inputType="textMultiLine"
android:singleLine="false"
android:textColor="#color/edit_text_text_color"
android:textSize="16dp" />
</LinearLayout>
<Button
android:id="#+id/SomeButton"
android:layout_width="match_parent"
android:layout_height="#dimen/dialog_button_height"
android:layout_margin="15dp"
android:text="text" />
</LinearLayout>
I have
android:windowSoftInputMode="adjustPan" >
set in my manifest.
Found the solution :
I put : getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
in the onCreateDialog callback
I also faced the same issue and resolved by keeping getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
inside oncreateview
Since SOFT_INPUT_ADJUST_RESIZE is deprecated starting android 30, you should use Window.setDecorFitsSystemWindows(boolean decorFitsSystemWindows)
Here is example for DialogFragment
class MyDialog extends DialogFragment {
#Override
public void onDestroyView() {
super.onDestroyView();
getDialog().getWindow().setDecorFitsSystemWindows(true);
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.my_dialog, container, false);
v.setOnApplyWindowInsetsListener((v1, insets) -> {
Insets imeInsets = insets.getInsets(WindowInsets.Type.ime());
v1.setPadding(0, 0, 0, imeInsets.bottom);
return insets;
});
getDialog().getWindow().setDecorFitsSystemWindows(false);
return v;
}
}
In my Activity I have a FrameLayout, that suppose to use as container for fragments.
In my fragment I got a ScrollView that doesn't respond. ScrollView contains TextView set android:layout_height="wrap_content", with text from my java code that clearly longer than the size of the ScrollView.
My fragment 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="#dimen/bookview.imageWidth"
android:layout_height="250dp"
android:id="#+id/bookView.image"/>
<TextView
android:textSize="#dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="#id/bookView.image"
android:id="#+id/bookView.name"/>
<TextView
android:textSize="#dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="#id/bookView.image"
android:layout_below="#id/bookView.name"
android:id="#+id/bookView.author"/>
<TextView
android:textSize="#dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="#id/bookView.image"
android:layout_below="#id/bookView.author"
android:id="#+id/bookView.pages"/>
<TextView
android:textSize="#dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="#id/bookView.image"
android:layout_below="#id/bookView.pages"
android:id="#+id/bookView.category"/>
<TextView
android:textSize="#dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="#id/bookView.image"
android:layout_below="#id/bookView.category"
android:id="#+id/bookView.publishingDate"/>
</RelativeLayout>
<ScrollView
android:layout_height="200dp"
android:layout_width="match_parent"
android:layout_gravity="end">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="#dimen/custom_book_text"
android:id="#+id/bookView.description"/>
</ScrollView>
</LinearLayout>
the xml of the activity:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/use.drawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="#dimen/user_custom_book_height"
android:id="#+id/user.customBookContainer"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/user.container"/>
</LinearLayout>
<include
layout="#layout/navigation_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
i use FrameLayout because i want to change the fragment in that area,in runtime.better idea? i like to hear.
i have tried to decrese the heigth of the ScrollView.
my fragment java code:
public class BookView extends Fragment {
private Bitmap bitmap;
private String name;
public static BookView newInstance(String book,Bitmap bitmap) {
Bundle args = new Bundle();
BookView fragment = new BookView();
fragment.bitmap = bitmap;
fragment.name = book;
fragment.setArguments(args);
return fragment;
}
public BookView() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_book_view, container, true);
Backend backend = BackendFactory.getInstance();
try {
Book b = backend.readBook(name);
TextView textView = (TextView)v.findViewById(R.id.bookView_name);
textView.setText(b.getBookName());
textView = (TextView)v.findViewById(R.id.bookView_author);
textView.setText(b.getAuthor());
textView = (TextView)v.findViewById(R.id.bookView_category);
textView.setText(b.getCategory().name());
textView = (TextView)v.findViewById(R.id.bookView_description);
textView.setText(b.getDescription());
textView = (TextView)v.findViewById(R.id.bookView_pages);
textView.setText(Integer.toString(b.getPages()));
textView = (TextView)v.findViewById(R.id.bookView_publishingDate);
textView.setText(b.getPublishingDate());
final ImageView imageView = (ImageView)v.findViewById(R.id.bookView_image);
if(bitmap != null){
imageView.setImageBitmap(bitmap);
} else{
ImageLoader imageLoader = new ImageLoader();
imageLoader.setListener(new ImageLoader.ImageTaskListener() {
#Override
public void onActionEnd() {}
#Override
public void onImageDownload(Bitmap bitmap) {
imageView.setImageBitmap(bitmap);
}
});
imageLoader.execute(b.getImage());
}
}
catch (Exception e) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(e.getMessage());
builder.create().show();
}
return inflater.inflate(R.layout.fragment_book_view, container, false);
}
}
imageLoader is a class i wrote,it extened AsyncTask for download image from a url and update the UI when it ready.
I think other parts (TextViews and ImageViews) of this fragment full all area of screen and ScrollView render out of screen.
I suggest you put all layout inside ScrollView.
like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/bookView.image"
android:layout_width="#dimen/bookview.imageWidth"
android:layout_height="250dp"/>
<TextView
android:id="#+id/bookView.name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/bookView.image"
android:textSize="#dimen/custom_book_text"/>
<TextView
android:id="#+id/bookView.author"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/bookView.name"
android:layout_toEndOf="#id/bookView.image"
android:textSize="#dimen/custom_book_text"/>
<TextView
android:id="#+id/bookView.pages"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/bookView.author"
android:layout_toEndOf="#id/bookView.image"
android:textSize="#dimen/custom_book_text"/>
<TextView
android:id="#+id/bookView.category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/bookView.pages"
android:layout_toEndOf="#id/bookView.image"
android:textSize="#dimen/custom_book_text"/>
<TextView
android:id="#+id/bookView.publishingDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/bookView.category"
android:layout_toEndOf="#id/bookView.image"
android:textSize="#dimen/custom_book_text"/>
</RelativeLayout>
<TextView
android:id="#+id/bookView.description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/custom_book_text"/>
</LinearLayout>
I assume you are able to see the fragment's view.
If so a few things to try:
Set the scroll view to fillViewPort="true"
and then set the text view to match parent since this is the only view in the scroll view. As a note you should really avoid using hard coded widths & heights (even dp heights).
Instead of returning
return inflater.inflate(R.layout.fragment_book_view, container, false);
just return the original view: v
Nother' bit of readability: instead of reassigning textview each time.
do:
((TextView)v.findViewById(R.id.blabla)).setText("BLA");
Edit:
I have tested this & it works.
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:fillViewport="true">
<TextView
android:id="#+id/faq_output_answer"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="match_parent" />
</ScrollView>
Try putting an empty view as the last item in your scrollview.
<View
android:layout_width = "match_parent"
android:layout_height = "50dp" />
This worked for me.
I'm using Shared Elements Transition between an imageView in a gridView adapter and an imageView in a details activity , but when i click on an item in the GridView the imageView dosen't start to animate from the right position it always starts under the original place, and when i hit back the image animates to the right place correctly so the glitch happens only when entering the new activity.
https://youtu.be/cprBHWPVNbk (i've slowed down the animation so that the glitch is clear).
In the BrowseFragment's OnCreate :
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView gridPoster = (ImageView) view.findViewById(R.id.movie_poster);
gridPoster.setTransitionName("poster" + position);
listener.onItemSelected(movie,gridPoster);
Then the BrowseActivity's listener starts the detailsActivtiy :
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
(this, posterView,posterView.getTransitionName());
Intent detailsIntent = new Intent(this, MovieDetalisActivity.class);
detailsIntent.putExtra(getString(R.string.movie_details_extra_key), movie);
detailsIntent.putExtra("transition",posterView.getTransitionName());
ActivityCompat.startActivity(this, detailsIntent, optionsCompat.toBundle());
Then in the DetailsFragment's OnCreate :
ImageView poster = (ImageView) rootView.findViewById(R.id.poster);
poster.setTransitionName(getActivity().getIntent().getStringExtra("transition"));
GridViewItem layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/gird_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#4e585c"
android:clipChildren="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="240dp"
android:id="#+id/movie_poster" />
<RelativeLayout
android:id="#+id/thumb_bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:gravity="center_vertical">
<TextView
android:id="#+id/movie_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:fontFamily="sans-serif"
android:textColor="#aaa"
android:textSize="16sp"
/>
</RelativeLayout>
</LinearLayout>
Part of the DetailsView layout :
<android.support.v4.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/scrollView"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:clipChildren="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.rashwan.popularmovies.MovieDetailsActivityFragment"
android:orientation="vertical"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="310dp"
android:orientation="horizontal"
android:padding="10dp"
android:baselineAligned="false"
android:clipChildren="false">
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:clipChildren="false">
<ImageView
android:layout_width="wrap_content"
android:minWidth="220dp"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:id="#+id/poster" />
</FrameLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:padding="5dp"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ReleaseDate"
android:id="#+id/release_date"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserRating"
android:id="#+id/user_rating"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:textAppearanceLarge"/>
</LinearLayout>
</LinearLayout>
And in my Theme i declared <item name="android:windowContentTransitions">true</item>i'm not using any custom animation although i tried some and i also tried to postpone the transition but nothing solved the problem.
I've found that the problem was that i'm using picasso library to load the images in the details fragment so i needed to use postponeEnterTransition(); in the details activity then in the details fragment i use getActivity().startPostponedEnterTransition(); to start the transition but only after the image is loaded using picasso.
Here's the code in the details fragment:
Picasso.with(getActivity()).load(posterUri).fit().into(poster, new Callback() {
#Override
public void onSuccess() {
poster.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
if (isLollipop) {
poster.getViewTreeObserver().removeOnPreDrawListener(this);
getActivity().startPostponedEnterTransition();
}
return true;
}
});
}
Try putting your classes in manifest.AS