I have a fragment with 2 embedded fragments.
I would like to have embedded fragment1 interact with embedded fragment2.
For example I have a button inside embedded fragment1, when I press on said button I would like it to update a TextView inside embedded fragment2.
Here's my main "parent" fragment
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragment
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment1"/>
<fragment
android:id="#+id/fragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment2"/>
</LinearLayout>
Here is my fragment1 class onCreateView method:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
val mainView = inflater.inflate(R.layout.fragment1, container, false)
val button = mainView.findViewById<Button>(R.id.button)
button.setOnClickListener {
/* Update TextView inside Fragment2 */
}
return mainView
}
Here is my fragment2 class onCreateView method:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
val mainView = inflater.inflate(R.layout.fragment2, container, false)
val textView = mainView.findViewById<TextView>(R.id.textview)
return mainView
}
Read on this:
https://developer.android.com/training/basics/fragments/communicating
This is the standard way. Basically create the Fragment1 Interface for the Activity to implement; assign a reference to Activity in Fragment as that interface; then find the other fragment from the Activity to call the fragment method for updating the textView.
Edit:
In the case of Fragments within fragments, you can implement the interface in the parent fragment and attach like this:
#Override
public void onAttach(Context context) {
super.onAttach(context);
try {
callback = (SomeInterface) getParentFragment();
} catch (ClassCastException e) {
throw new ClassCastException("Parent fragment must implement SomeInterface");
}
}
However, as mentioned in the article, this is the old way. The modern way is to communicate between a shared ViewModel.
Related
I am developing an application that uses the tablayout and contains 3 guides. The first is for general user information, the second guide is for additional information and the last guide is for the user to draw on the screen. is a third company that has problems, even with swiping disabled, when making drawing movements, the user ends up returning to the previous tab. So, I would like to know how to disable the movement of the swip on this screen, even with the movement between tabs it is already disabled with the sliding movement, without making it impossible for the drawing to be made.
One thing to note is that when you start drawing from the bottom up or up and down, you can draw without changing as guides, even if you are going somewhere later. However, if you start drawing
One thing I noticed, that when I start to draw from the bottom up or up and down, I can draw without changing the tabs, even if I go anywhere afterwards. However, if I start drawing anywhere, he understands that it is not the drawing but that I want to change tabs. How can I fix this?
class Main2Activity : AppCompatActivity() {
#SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager)
val viewPager: ViewPager = findViewById(R.id.viewPager)
viewPager.adapter = sectionsPagerAdapter
viewPager.setOnTouchListener { _, _ -> return#setOnTouchListener true }
val tabs: TabLayout = findViewById(R.id.tabs)
tabs.setupWithViewPager(viewPager)
}
}
fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ufrn.dissertation.activities.Main2Activity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?actionBarSize"
android:padding="#dimen/appbar_padding"
android:text="#string/app_name"
android:textAppearance="#style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Image Fragment
class ImagesFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_imagens, container, false)
...CODE DRAWING...
Drawind starting from bottom/up or up/down
Drawind starting from left/right or right/left
Migrate to version 2 of the viewPager. To do this, follow the steps below:
- Add the necessary implementations:
implementation 'com.google.android.material:material:1.3.0-alpha01'
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
- update your layout:
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchorGravity="bottom"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
- Update yout adapter:
class SectionsPagerAdapter(
private val activity: FragmentActivity
) : FragmentStateAdapter(activity) {
override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> ProfileFragment()
1 -> TreatmentFragment()
else -> ImagesFragment()
}
}
fun getPageTitle(position: Int): CharSequence =
activity.resources.getString(TAB_TITLES[position])
override fun getItemCount(): Int = TAB_TITLES.size
companion object {
private val TAB_TITLES = arrayOf(
R.string.tab_text_1,
R.string.tab_text_2,
R.string.tab_text_3
)
}
}
- Your PageViewModel:
class PageViewModel : ViewModel() {
private val _index = MutableLiveData<Int>()
val text: LiveData<String> = Transformations.map(_index) {
"Hello world from section: $it"
}
fun setIndex(index: Int) {
_index.value = index
}
}
- Your PlaceholderFragment:
class PlaceholderFragment : Fragment() {
private lateinit var pageViewModel: PageViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pageViewModel = ViewModelProviders.of(this).get(PageViewModel::class.java).apply {
setIndex(arguments?.getInt(ARG_SECTION_NUMBER) ?: 1)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.fragment_main2, container, false)
val textView: TextView = root.findViewById(R.id.section_label)
pageViewModel.text.observe(viewLifecycleOwner, Observer {
textView.text = it
})
return root
}
companion object {
private const val ARG_SECTION_NUMBER = "section_number"
#JvmStatic
fun newInstance(sectionNumber: Int): PlaceholderFragment {
return PlaceholderFragment().apply {
arguments = Bundle().apply {
putInt(ARG_SECTION_NUMBER, sectionNumber)
}
}
}
}
}
- And your MainAcitivity:
class MainActivity : AppCompatActivity() {
#SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
val sectionsPagerAdapter = SectionsPagerAdapter(this)
val viewPager = findViewById<ViewPager2>(R.id.viewPager).apply {
adapter = sectionsPagerAdapter
isUserInputEnabled = false
}
val tabs: TabLayout = findViewById(R.id.tabs)
TabLayoutMediator(tabs, viewPager, true) { tab, position ->
tab.text = sectionsPagerAdapter.getPageTitle(position)
}.attach()
}
}
That way it will fix your problem
You should migrate from ViewPager to ViewPager2
You should use
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewpager"
app:layout_anchor="#id/tabs"
app:layout_anchorGravity="bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
instead of
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
There are built-in methods to disable swiping in ViewPager2
To disable swiping in ViewPager2
myViewPager2.setUserInputEnabled(false);
To enable swiping in ViewPager2
myViewPager2.setUserInputEnabled(true);
For more information please check out below link
Proper implementation of ViewPager2 in Android
Migrate from ViewPager to ViewPager2
Create swipe views with tabs using ViewPager2
if you still want to use ViewPager then please take look in this post How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?
I have created an app which basically has navigation drawer and I wish to load an fragment "home" whenever the activity launches instead of main activity.
Any idea how to do it.
You can call this method to view Fragments. In your case call this method on your onCreate()
//Fragment Changer
public void changeFragment(Fragment targetfragment) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_fragment, targetfragment, "fragment")
.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.addToBackStack(null)
.commitAllowingStateLoss();
}
Example Usage
changeFragment(new YourFragment());
Basic solution can be implementing something like the below code in your onCreate method.
// get fragment manager
FragmentManager fm = getFragmentManager();
// replace
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.main_layout, new HomeFragment());
ft.commit();
Your Activity:
public class MainActivity extends AppCompatActivity {
public static final String TAG = MainActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
}
public String getHelloMessage() {
return "Hello!";
}
}
Your View:
public class MainView extends Fragment {
// Declarations
private Button testButton;
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.main_view, container, false);
// Getting the reference of controller from Application
MainController mainController = Application.getInstance().getMainController();
// Initializing view objects
testButton = view.findViewById(R.id.test_button);
// Setting actions
testButton.setOnClickListener(mainController.getTestAction());
return view;
}
// Reference to the view Object
public Button getTestButton() {
return testButton;
}
Your main_activity.xm lto connect the fragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/containerMainView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/mainView"
android:name="com.template.views.MainView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Your main_view.xml file your final view definition
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/say_hello" />
</RelativeLayout>
I am trying to create a viewpager that swipes through 3 different fragments each with a different toolbar. I have implemented the new toolbar in an activity before and got it to work however I am trying to get it to work with fragments
Here is the fragment code
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout resource that'll be returned
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
mToolbar = (Toolbar) rootView.findViewById(R.id.toolbar_home);
if (mToolbar != null) {
setSupportActionBar(mToolbar);
}
mToolbar.setTitle(null);
return rootView;
}
I am extending my fragment with Fragment, however I am getting the error
Cannot resolve method setSupportActionBar
I am not sure how to resolve this, if I remove the setSupportActionBar code will it stop working with certain devices?
Fragments don't have such method setSupportActionBar(). ActionBar is a property of Activity, so to set your toolbar as the actionBar, your activity should extend from ActionBarActivity and then you can call in your Fragment:
((ActionBarActivity)getActivity()).setSupportActionBar(mToolbar);
UPDATE
If you're using AppCompatActivity :
((AppCompatActivity)getActivity()).setSupportActionBar(mToolbar);
I have seen a lot of answers mentioning to setSupportActionBar for toolbar inside Fragment but this approach may go wrong if you are having a a toolbar in Activity and a separate Toolbar in Fragment.
As you shift setSupportActionBar from Activity's Toolbar to Fragment's toolbar, You may face duplication of MenuItem even you try to override using setHasOptionsMenu(true).
Secondly If you want to update Activity's Toolbar you see your changes are not reflected because of setSupportActionBar inside your Fragment.
So in order to avoid this I recommend to use toolbar methods like this inside fragment to inflate menu and use
toolbar = (Toolbar) view.findViewById(R.id.toolbar_frag);
toolbar.inflateMenu(R.menu.frag_menu_items);
Menu menu = toolbar.getMenu();
and use Toolbar.OnMenuItemClickListener interface to receive with menuItems click events.
Edit (Section Copied from MrEngineer13 answer)
and if you are worried about the back button you can set it like this
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_action_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//What to do on back clicked
}
});
Base on #Faisal Naseer answer. Here is the full example (with few notes) for using custom Toolbar
with navigation and menu in Fragment
fragment_home.xml
<androidx.constraintlayout.widget.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="match_parent"">
...
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar_home"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="Home" />
</androidx.constraintlayout.widget.ConstraintLayout>
HomeFragment.kt
class HomeFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
// setHasOptionsMenu(true): don't need this anymore
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_home, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
toolbar_home.setNavigationIcon(R.drawable.ic_back) // need to set the icon here to have a navigation icon. You can simple create an vector image by "Vector Asset" and using here
toolbar_home.setNavigationOnClickListener {
// do something when click navigation
}
toolbar_home.inflateMenu(R.menu.menu_home)
toolbar_home.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_add -> {
// do something
true
}
R.id.action_update -> {
// do something
true
}
else -> {
super.onOptionsItemSelected(it)
}
}
}
}
}
menu_home.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_add"
android:title="#string/add_device"
app:showAsAction="never" />
<item
android:id="#+id/action_update_room"
android:title="#string/update_room"
app:showAsAction="never" />
</menu>
Hope it help
With the new AppCompatActivity you should call it instead of ActionBarActivity:
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
You can add toolbar in Fragments using this
((YOUR_ACTIVITY) getActivity()).getDelegate().setSupportActionBar(toolbar);
I use Kotlin. In my case Activity is a child class of AppCompatActivity and theme of activity is inherited from
Theme.MaterialComponents.DayNight.NoActionBar
So my Activity doesn't have action bar, but my Fragment do.
I will show you how to use toolbar with defined menu as a SupportActionBar in fragment
This is my Toolbar
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:navigationContentDescription="Back to the previous question"
android:background="?attr/colorPrimary"
tools:title="#string/posts" />
This is my Fragment's methods:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
(context as AppCompatActivity).setSupportActionBar(_bind?.toolbar)
setHasOptionsMenu(true)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.toolbar_menu_post_list, menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when(item.itemId)
{
R.id.add -> {
val post = Post()
postListViewModel.addPost(post)
callbacks?.onItemSelected(post.id)
return true
}
else -> super.onOptionsItemSelected(item)
}
}
I am trying to get a fragment to show that contains an EditText and a button. I am new to using fragments, so I am not sure exactly what the error message I get when trying to create the fragment means.
I have a class that extends Fragment, this is where the EditText and button are created.
public class EditNameFragment extends android.support.v4.app.Fragment {
EditText editText;
ImageButton button;
public EditNameFragment(){
}
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.edit_name_dialog, container, false);
editText = (EditText) view.findViewById(R.id.editTextDialog);
button = (ImageButton) view.findViewById(R.id.submitNewItemButtonDialog);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//stuff
}
});
return view;
}
Here is edit_name_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="#+id/edit_name_dialog"
>
<EditText
android:id="#+id/editTextDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton
android:id="#+id/submitNewItemButtonDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
And here in my main activity (which must extend FragmentActivity because of another part) is where I try to set up my Fragment. I think it has something to do with what id I am referencing. I have seen some people using container classes when using fragments, but I do not understand why this is done.
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
EditNameFragment fragment = new EditNameFragment();
fragmentTransaction.add(R.id.edit_name_dialog, fragment, "tag");
fragmentTransaction.commit();
I get the error message when trying to run the code above
No view found for id 0x7f09002a (com.myapp:id/edit_name_dialog) for fragment EditNameFragment
If anyone could explain what I am missing here/ why people use container classes, that would be great. I know some people add fragments using XML, but I would like to do this only using java.
EDIT
I have added a class that extends FragmentActivity, following the model for a container class
public class EditNameFragmentActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_name_fragment_container);
}
}
Is the parameter for setContentView supposed to be the layout, or an id?
Here is the xml file that defines where the fragment should be
edit_name_fragment_container.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fragment android:name="com.returnjump.spoilfoil.EditNameFragment"
android:id="#+id/edit_name_fragment_container"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/edit_name_fragment" />
</LinearLayout>
So for the parameter in
fragmentTransaction.add(R.id.edit_name_dialog, fragment, "tag");
this is supposed to reference the id of the fragment, correct?
It still gives me the same error, what am I missing?
There are basically two ways to add a fragment to an activity like the documentation say:
"statically": by declaring the fragment inside the activity's layout file.
"dynamically": adding the fragment programmatically. Like you tried to do.
Here is the documentation: http://developer.android.com/guide/components/fragments.html
If you wish to add it dynamically, here is the documentation part that you want to read:
At any time while your activity is running, you can add fragments to your activity layout. You simply need to specify a ViewGroup in which to place the fragment.
To make fragment transactions in your activity (such as add, remove, or replace a fragment), you must use APIs from FragmentTransaction. You can get an instance of FragmentTransaction from your Activity like this:
FragmentManager fragmentManager = getFragmentManager()
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
You can then add a fragment using the add() method, specifying the fragment to add and the view in which to insert it. For example:
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
The first argument passed to add() is the ViewGroup in which the fragment should be placed, specified by resource ID, and the second parameter is the fragment to add.
Once you've made your changes with FragmentTransaction, you must call commit() for the changes to take effect.
And about why to use dynamic fragments instead of static fragments, it has been made for interactive UI allowing you to simply handle different fragments into one activity as you please.
I have one activity that holds multiple fragments. Each fragment implements my UpdateRequest interface, where each of these fragments do some asynctask and downloads data from web service. My problem is that I don't really understand how to update existing fragments. I read this
Android Refreshing Fragment View after AsyncTask
but I still can't figure out how to locate views of each fragment and then update them. I'll give an example:
There's an UserFragment, which should represents user profile:
public class UserFragment extends SherlockFragment implements
UpdateRequest {
View rootView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_user_info,
container, false);
return rootView;
}
...
public void update(final OnFragmentUpdatedListener context) {
...
asyntask
...
}
}
And fragment_user_info looks like this:
<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" >
<ImageView
android:id="#+id/fragment_user_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/image_of_user" />
<TextView
android:id="#+id/fragment_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/user_info" />
</RelativeLayout>
What I want is to locate instance of UserFragment and then in its AsyncTask.onPostExecute() method change text in fragment_user_name textView to something that asynctask returns.
The easiest way to do this is to create a final variable in the fragment to hold a reference to the TextView. Then the AsyncTask, being an anonymous inner class of the fragment, will have direct access to it. So, something like this:
public class UserFragment extends SherlockFragment implements UpdateRequest {
private View rootView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_user_info, container, false);
return rootView;
}
...
public void update(final OnFragmentUpdatedListener context) {
final TextView userNameView = (TextView) rootView.findViewById(R.id.fragment_user_name);
...
asyntask
...
onPostExecute() {
userNameView.setText(....);
}
}