Creating a clickable android Layout

I have a relative layout that contains two fragments. My java code is designed to decide which fragment to choose based on the orientation of the screen. I want to have the app switch to a new activity when the screen is touched but I can't figure out how to code it up. I tried setting the main activity xml to be clickable and setting up the intent there but it's not working. I also tried allowing the fragment xml's to be clickable but I can't set an intent with the the fragment java file. My main activity looks like this if anyone can help.

public class StartPage extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout useMe; FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Configuration configInfo = getResources().getConfiguration(); if (configInfo.orientation == Configuration.ORIENTATION_LANDSCAPE) { StartPageLandscapeFragment startPageLandscapeFragment = new StartPageLandscapeFragment(); fragmentTransaction.replace(, startPageLandscapeFragment); useMe = (RelativeLayout) findViewById(; } else { StartPagePortraitFragment startPagePortraitFragment = new StartPagePortraitFragment(); fragmentTransaction.replace(, startPagePortraitFragment); useMe = (RelativeLayout) findViewById(; } fragmentTransaction.commit(); useMe.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(StartPage.this, Question1.class); startActivity(intent); } }); } }


you need to setContentView(R.layout.your's layout); for this activity

Where exactly you set the onClickListener for your RelativeLayout? You need something like

useMe.setOnClickListener(new View.OnClickeListener())

After further investigation i found out I was using fragments in a weird way. I was using fragments to determine layouts dependent on orientation without knowing I could use a seperate layout folder all together to do that. I removed all the fragment work and now everything is good.

Category:android Time:2018-11-20 Views:2

Related post

  • Who to create a proportional Android layout? 2010-08-08

    I'm trying create a scaling layout for an Android application. The whole screen should contain two areas. The top 3/4 of the screen should be a MapView showing a certain area. The remaining quarter of the screen should contain some textual informatio

  • How can I create 2 rows of buttons in android layout.xml file 2009-08-12

    I try to create 2 rows of buttons in android layout.xml file. The first row is left-aligned, the second row is center-aligned. Here is what I did, but I end up getting 1 row of buttons. Can you please tell me what am I doing wrong? enter code here

  • Android Layout designer doesn't open XML file created in IntelliJ 2011-06-08

    My main working tool is IntelliJ. So I use it to create XML files and layouts for Android activities. However, if I open such XML file in Eclipse, it does not recognize it as layout file and does not load its GUI designer (I open XML file via Eclipse

  • How can I create HTML equivalents of Android layouts? 2011-07-04

    I want to be able to generate HTML representations of existing Android layouts. In my case it's to help document some of my applications for users who are blind, otherwise simple screenshots would probably suffice. Since layouts in Android use XML I

  • Clickable relative layout 2011-08-09

    I have a clickable relative layout with textviews that I want to create an outline around to allow users to realize that it is clickable, but I'm not sure how to go about doing this. Any help would be appreciated. EDIT: I've already implemented click

  • Android layout as button with selectable functionality 2012-01-11

    I'm trying to create a button-like component, with a left-aligned ImageView and then 2 TextViews to the right of the ImageView, stacked one above the other and formatted differently, like the following example:. __________________________ | | | |----

  • Re-usable android layouts 2009-11-23

    I was wondering how everyone re-uses android layouts and components? Do you do the old copy/paste the existing code into the project, or is there a way to include the layouts and components into a jar file for re-use? EDIT: For example if I have a li

  • Need help in using android layout trick #1 2010-02-09

    I have read this blog entry about using relative layout to optimize layout in ListView: I have used this layout for my ListView Item (with a slight modification of the exampl

  • Eclipse crashes when I invoke Android Layout Editor 2010-02-27

    I'm new to Android & Eclipse. I've downloaded Eclipse and the Android ADT and created an ultra-simple Hello World app (has only auto-generated .java and .xml files). Eclipse CRASHES (closes after a very brief pause) when I do the following: In Pa

  • Can I underline text in an android layout? 2010-03-07

    How can I define underlined text in an Android layout xml file? --------------Solutions------------- It can be achieved if you are using a string resource xml file, which supports HTML tags like <b></b>, <i></i> and <u>

  • Is there a good tool for doing Android layout design? 2010-05-06

    I have tried DroidDraw and the Eclipse layout editor and both seem very difficult to create anything other than very simple layouts. I find myself dropping back to the XML file to be able to manipulate it. Has anyone found any good tools to design th

  • Android layouts under subfolders 2010-11-18

    Is it possible to create subfolders under res/layout and place the layout XML files there so that one can call a view like setContentView(R.layout.questions.create); or setContentView(R.layout.questions/create); ? --------------Solutions-------------

  • How to create marquee in Android using only java code without xml 2010-12-13

    I need to create Marquee in Android using only java code without using xml? Please provide me with resources to program in Android using only Java code without using xml. --------------Solutions------------- Start from here to learn how you can creat

  • Want help to make Android layout same like attachd image 2011-02-10

    I am getting stuck with making android screen layout same like i have in my iPhone application. The iPhone screen layout is given in below image. Please anyone can help me out to make same screen for android. You can give me some idea with having som

  • Advanced Explanation of Android Layout Properties? 2011-02-17

    I'm on a quest to learn how to layout components properly in Android. I'm a seasoned CSS/MXML developer and am having the hardest time getting a full understanding of layout properties in Android components. One thing is I'm not sure the differences

  • Android layout: Quadratic views 2011-03-16

    In an Android application I need to add a view to my RelativeLayout that obeys the following rules: The view should be quadratic, i.e. the height and the width of the view must match. The view should fill the whole WIDTH. It should look like this (th

  • Android layout folders: layout, layout-port, layout-land 2011-03-23

    I'm not sure to have understood well the role played by the several Android /res/layout folders. layout: general layouts layout-port: layout for widget that must change for portrait orientation layout-land: layout for widget that must change for land

  • Best way to define Android layout files for multiple devices? 2011-05-05

    What is the standard/best way to define sizing for elements in Android layout files to account for Android devices with all types of screens? For example: I've been using a LinearLayout to arrange multiple child elements (TextViews, Buttons) one afte

  • Creating a custom android UI 2011-05-17

    does anyone know how I would get started creating a custom android UI? it wouldn't be an app. Once you install it, it would change the appearance of your UI until you uninstall it. I've done some research but it doesn't seem to be possible/available

Copyright (C), All Rights Reserved.

processed in 2.027 (s). 14 q(s)