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

  • Home
  • SEARCH
  • 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 8413107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:51:12+00:00 2026-06-10T00:51:12+00:00

I am a newbie in Android programming and I have this problem: In this

  • 0

I am a newbie in Android programming and I have this problem:

In this simple example, when I click on start button, I run a fragment. When I click on alarm button, I write in a log file.

Now, if I click first the start button, later the alarm button don’t run. I think the problem is the fragment don’t leave the interaction with user. Can you help me?
best regads
A.

public class MainActivity extends FragmentActivity {
private static final String FRAG1_TAG = MainActivity.class.getCanonicalName() +".fragment1";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button buttonStart = (Button) findViewById(R.id.buttonStart);
    buttonStart.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            Log.i("exemple", "start button Start !!!!!!");
            goFragment();

        }
    }); 
    Button buttonAllarm = (Button) findViewById(R.id.buttonAllarm);
    buttonAllarm.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {            
        Log.i("exemple", "start button allarm !!!!!!");
        }// fine onClick    
    });// fine onClickListner
}

void goFragment() {

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction xact = fm.beginTransaction();
    if (null == fm.findFragmentByTag(FRAG1_TAG)) {
        xact.replace(android.R.id.content, new ListFramment(), FRAG1_TAG);
         xact.addToBackStack (null);   // questo serve devi metterlo
            xact.commit();
    }
}

this is the fragment

      public class ListFramment extends ListFragment {
       // onCreate     
        @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.activity_main, null);
    AppLog.logString("Parte onCreateView");
    return view;
}   

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    AppLog.logString("Parte onActivityCreated");
    ArrayList<Map<String, String>> list = buildData();

    String[] from = { "name", "purpose" };
    int[] to = { android.R.id.text1, android.R.id.text2 };

    SimpleAdapter adapter = new SimpleAdapter(getActivity(), list,
    android.R.layout.simple_list_item_2, from, to);
    setListAdapter(adapter);

}

    private ArrayList<Map<String, String>> buildData() {
    ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
    list.add(putData("Android", "Mobile"));
    list.add(putData("iPhone", "iPhone"));
    return list;
    // TODO Auto-generated method stub

}

private HashMap<String, String> putData(String name, String purpose) {
    HashMap<String, String> item = new HashMap<String, String>();
    item.put("name", name);
    item.put("purpose", purpose);
    return item;
}
}
  • 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-10T00:51:14+00:00Added an answer on June 10, 2026 at 12:51 am

    Your problem is here:

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_main, null);
    AppLog.logString("Parte onCreateView");
    return view;
    }   
    

    Your Fragment is inflating the same layout as the Activity that created it. But the Fragment does not have any onClickListeners. I suspect that the Fragment layout is covering up the Activity layout, duplicating it exactly, with non-functional buttons. That would explain why the button click works only the first time.

    It would be normal for the Fragment to have its own layout, different from the Activity.

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

Sidebar

Related Questions

This might sound stupid, but I'm seriously a newbie at Android programming. I have
I am a complete Android programming newbie. I have completed some tutorial examples like
I am newbie in android. In android I trying to run a simple work.
I'm a newbie in Android development. Let me explain my problem. I've have a
I am a newbie to android programming I have two listviews in my activity
Scala/Android newbie question. I'm trying to rewrite this simple code from Java to Scala.
Android newbie here. I'm using this tutorial to show some rows that I fetch
i am newbie for Android Development. i don't have any idea for creating Scientific
I am a newbie to android development and am trying to develop a simple
I have the following thing to achieve in Android(newbie). I have an xml which

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.