Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8543407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:17:39+00:00 2026-06-11T12:17:39+00:00

I am working with the android support library, to be able to use fragments

  • 0

I am working with the android support library, to be able to use fragments from Froyo, and the Sherlock extension, to show an ActionBar.

I have a fragment which shows three textViews and a button, and I want to be able to change the button text dinamically, depending on the content of the Intent. The problem is that when I call button.setText(String text), a second button appears. However, I’ve called button.getId() when clicking on each of them, and the Id is the same. I don’t have a clue of why this is happening, so I’d appreciate some help.

The app is run on a Samsung Galaxy S, with Android 2.3.3. I can’t upload a screen capture because I don’t have enough reputation yet 🙁

This is the code:

FRAGMENT

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.actionbarsherlock.app.SherlockFragment;
import com.parse.ParseUser;
import com.tiempoderodar.egdf.EGDF_App;
import com.tiempoderodar.egdf.R;
import com.tiempoderodar.egdf.security.Constants;

/**
 * @author Daniel Leal López
 *
 */
public class ChapterDetailsFragment extends SherlockFragment{

    private Button b;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("ChapterDetailsFragment", "Created");
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ParseUser user = EGDF_App.getUser(); 
        b = (Button) getSherlockActivity().findViewById(R.id.buttonWatchChapter);
        if (user != null){

            String chapterNumber = "";
            Bundle extras = getSherlockActivity().getIntent().getExtras();
            String s = extras.getString(Constants.CHAPTER_NUMBER_PARSE);
            if((s != null)&&(!s.equals(""))){
//              tvNumber.setText(s);
                chapterNumber = "Chapter_" + s;
                Log.i("Properties", s);
            }
            String seen = user.getString(chapterNumber);
            if((seen != null)&&(!seen.equals(""))&&(seen.equals(Constants.USER_CHAPTER_SEEN))){
                b.setText("Second text: "+getString(R.string.watch_chapter_button_text));
                Log.i("BUTTON CHANGED", "Text changed to watch");
            }               
            else if((seen != null)&&(!seen.equals(""))&&(seen.equals(Constants.USER_CHAPTER_NOT_SEEN))){
                b.setText("Second text: " + getString(R.string.buy_chapter_button_text));
                Log.i("BUTTON CHANGED", "Text changed to buy");
            }else{
                Log.w("DEV ERROR", "Chapter text not obtained");
            }
        }else{
            Log.w("DEV ERROR", "ParseUser is null in EGDF_App!!!");
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.chapter_details, container, false);
        return view;
    }

    public void setText(String item) {
        getSherlockActivity().getSupportActionBar().setTitle(item);
    }

    public void setButtonText(String text){
        b.setText(text);
    }

}

Activity

import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.actionbarsherlock.app.SherlockFragmentActivity;

public class ChapterDetailsActivity extends SherlockFragmentActivity {

    private Bundle extras;
    MediaPlayer mMediaPlayer;

    private String chapterNumber;
    private boolean isChapterSeen;
    //  private int duration;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_chapter_details);

        if (savedInstanceState == null) {
            // During initial setup, plug in the details fragment.
            ChapterDetailsFragment details = new ChapterDetailsFragment();
            details.setArguments(getIntent().getExtras());
            getSupportFragmentManager().beginTransaction().add(
                    android.R.id.content, details).commit();
        }

    }

    public void watchChapter(View view){
        Log.i("Button", "Watch chapter button PRESSED");
        Button b = (Button) view;

        Log.d("BUTTON PARENT VIEW", b.getParent().getClass().getName());
        Log.d("BUTTON ID", String.valueOf(b.getId()));
        String loadChapter = getString(R.string.load_chapter_button_text);
        String watchChapter = getString(R.string.watch_chapter_button_text);
        String buyChapter = getString(R.string.buy_chapter_button_text);

    }

    @Override
    protected void onPause() {
        Log.i("Activity lifecycle", "On pause called");
        super.onPause();
    }

    @Override
    protected void onStop() {
        Log.i("Activity lifecycle", "On stop called");
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        Log.i("Activity lifecycle", "On destroy called");
        super.onDestroy();
        EGDF_App.releaseMediaPlayer();
    }

    @Override
    protected void onResume() {
        Log.i("Activity lifecycle", "On resume called");
        super.onResume();
    }

    @Override
    protected void onStart() {
        Log.i("Activity lifecycle", "On start called");
        super.onStart();
    }
}

Activity 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" >

    <fragment
        android:id="@+id/chapterDetailsFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.tiempoderodar.egdf.content.ChapterDetailsFragment" />

</LinearLayout> 

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" >

    <TextView
        android:id="@+id/textViewChapterNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="30dip" />

    <TextView
        android:id="@+id/textViewChapterSeason"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="30dip" />

    <TextView
        android:id="@+id/textViewChapterSinopsis"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="30dip" />

    <TextView
        android:id="@+id/textViewChapterCredits"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="30dip" />

    <Button 
        android:id="@+id/buttonWatchChapter"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/watch_chapter_button_text"
        android:layout_gravity="center"
        android:onClick="watchChapter"/>

</LinearLayout>

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:17:40+00:00Added an answer on June 11, 2026 at 12:17 pm

    I think I might have found the problem. I was calling

    b = (Button) getSherlockActivity().findViewById(R.id.button); 
    

    but it should be

    b = (Button) getView().findViewById(R.id.button);
    

    With that change it works correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android app, working fine with fragments, I need to show a
I'm having troubles working with fragments to the 2.2 platform. I imported the android-support-v4.jar
i am working on android and trying to read a value from my preference
I am working on Android Application. Now I have requirement of search the entered
I am currently working on android project where I want to have a text
Building an app using android.support.v4.app , targeting API level 8. Everything's working as planned
I'm working on an Android application where I'd like to have the largeHeap and
I'm trying to get an html5 demo page working on Android 2.1, have tried
Has anybody gotten the support library to render a grid layout correctly in Android
I am working on a Unity3d for Android project. Using the documentation from Unity:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.