fragment

安卓viewpager2通过fragment和tablayout使用

孤街醉人 提交于 2019-12-20 04:12:22
1,定义三个fragment页面 2,页面布局如下 3,在父页面中添加如下代码: //给viewpager建立适配器 viewPager.setAdapter(new FragmentStateAdapter(this) { @NonNull @Override public Fragment createFragment(int position) { switch (position) { case 0: return new Fragment(R.layout.fragment_rotate); case 1: return new Fragment(R.layout.fragment_scale); default: return new Fragment(R.layout.fragment_translate); } } @Override public int getItemCount() { return 3; } }); //tab与下面的viewpager对应 TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(tabLayout,viewPager, new TabLayoutMediator.TabConfigurationStrategy() { @Override public void

Android Fragment lifecycle issue (NullPointerException on onActivityResult)

吃可爱长大的小学妹 提交于 2019-12-20 03:24:08
问题 I get an issue which for I cannot find any explanation. I have a FragmentActivity that displays fragments using a TabManager, as follows : public class WorkOrderFormTabFragmentActivity extends FragmentActivity { TabHost mTabHost; TabManager mTabManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.work_order_form_tab_new); mTabHost = (TabHost)findViewById(android.R.id

Reload Fragment

自古美人都是妖i 提交于 2019-12-20 02:59:17
问题 I am just curious, as I have set up Fragment tabs in a FragmentActivity, how to reload a fragment either from the FragmentActivity, or from the Fragment itself, to just purge and reload that tab. I essentially need the same thing that happens when I reselect the tab to happen, when it replaces the fragment. Is there a simple way to do this and reload the fragment ? 回答1: Create a method that begins a FragmentTransaction, detaches the fragment, and commits. Then begin a new FragmentTransaction

Android - Multiple fragments in ONE tab

你说的曾经没有我的故事 提交于 2019-12-20 02:13:57
问题 I searched a lot in the web about the possibility to have multiple fragments in one action bar tab. This question comes closest to my needs but the code is not working. Is there another possibility to include multiple fragments in one tab? This is the StartActivity public class StartActivity extends FragmentActivity implements ActionBar.TabListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start); // Set

Access fragment from adapter

て烟熏妆下的殇ゞ 提交于 2019-12-20 01:35:20
问题 The idea is i have a listview where each item is a product, when I click in the item, I need to go to another Fragment from the click which is inside the adapter of the listview. My adapter is: package info.android.adapter; import info.android.ProductFragment; import info.android.R; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.view.LayoutInflater; import android.view

Access fragment from adapter

[亡魂溺海] 提交于 2019-12-20 01:34:46
问题 The idea is i have a listview where each item is a product, when I click in the item, I need to go to another Fragment from the click which is inside the adapter of the listview. My adapter is: package info.android.adapter; import info.android.ProductFragment; import info.android.R; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.view.LayoutInflater; import android.view

Access fragment from adapter

半城伤御伤魂 提交于 2019-12-20 01:34:21
问题 The idea is i have a listview where each item is a product, when I click in the item, I need to go to another Fragment from the click which is inside the adapter of the listview. My adapter is: package info.android.adapter; import info.android.ProductFragment; import info.android.R; import java.util.ArrayList; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.view.LayoutInflater; import android.view

onActivityResult not called in fragment android [duplicate]

江枫思渺然 提交于 2019-12-20 01:13:29
问题 This question already has answers here : onActivityResult is not being called in Fragment (36 answers) Closed 2 years ago . This is my code to take picture from gallery. public class FragmentLayout1 extends Fragment implements OnClickListener { View root; Context c; Button add_image; DialogAddImage image; RelativeLayout layout_image; String path; RunAnimations anima; public void setContext(Context c){ this.c = c; Constants con = new Constants(c); } @Override public View onCreateView

how to call function from other fragment class

烈酒焚心 提交于 2019-12-19 12:08:03
问题 I'm trying to call this function public void arrowClick() is inside my main fragment public class CounterMain extends Fragment implements View.OnClickListener{ the fragment is extend android.support.v4.app.Fragment I want to call this function from another Custmoe Dialog fragment public class CustmoeDialog extends DialogFragment { I tried ((CounterMain)getActivity()).arrowClick(); but I can't use it it says android.support.v4.app.Fragment cannot be cast to my.example.CounterMain and the

How to display text in a TextView inside a Fragment

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 12:02:40
问题 Seems like a simple question to me, but I can't figure it out. I have this code inside my Fragment: myTextView.setText("Test"); However, this code brakes my app and I am unsure why. Perhaps this is a conflict with Views, but I still don't understand why it wont work. Any suggestions? 回答1: How did you set the content? Edited my answer :) try this @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout