1

I'm doing a simple Bluetooth App, to control the window of a car (only for research).

Layout should be two Buttons (Window up and Window down) and a TextView to printed responses on my actions and parameters.

Problem is, that both buttons won't appear in my app :(

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="@string/btn_window_up" />

<Button
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/btn_window_up"
    android:text="@string/btn_window_down" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/btn_window_down"
    android:text="&quot;Demo ADK V1.0&quot;" />

</RelativeLayout>

Does anyone has a suggestion how I can solve this?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    RxThread rxThread = new RxThread();
    MessageStructure demoTxMsg = new MessageStructure();

    ReturnCode returnCode = null;
    ArrayList<String> deviceList = new ArrayList<String>();

    Button btnWindowDown = (Button) findViewById(R.id.btn_window_down);
    Button btnWindowUp = (Button) findViewById(R.id.btn_window_up);

    tv = new TextView(this);
}

Here the Java-Code

and the manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ixxat.adk.demo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="13" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Demo_ADKActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Fraggles
  • 463
  • 4
  • 20
  • What is the problem ? Buttons are already displayed above Textview. – Hardik Joshi Dec 18 '13 at 10:48
  • can you elaborate your problem? is it not displayed in device or in xml page itself – Yogamurthy Dec 18 '13 at 10:49
  • they dont appear in the app :( – Fraggles Dec 18 '13 at 10:49
  • 2
    Okey! post your JAVA code. – Hardik Joshi Dec 18 '13 at 10:50
  • can you post you code here – Yogamurthy Dec 18 '13 at 10:50
  • Question updated above. Its not the complete code, cause of the length, but in my opinion the relevant vode for layout – Fraggles Dec 18 '13 at 10:55
  • 1
    what is the name of your layout file? is it main? cause maybe there's a chance that you're pointing on the wrong layout file. Also do you get errors when you try to run your app? – KaHeL Dec 18 '13 at 10:56
  • layout is main.xml also no errors on running – Fraggles Dec 18 '13 at 10:58
  • well that is weird cause it should be working in case. Can you also provide your AndroidManifest.xml and the name of your Java class file that calls this main.xml layout? – KaHeL Dec 18 '13 at 11:02
  • manifest added in original post, name of the java class file: "Demo_ADKActivity" – Fraggles Dec 18 '13 at 11:07
  • I'm not sure if this is the reason or not as I can't test for myself at the moment. But your `layout_below` is using `@+id/btn_window_down` for example. But the + is not necessry. It should just be `android:layout_below="@id/btn_window_down"` The + is only used when creating the id for the first time – Dreagen Dec 18 '13 at 11:09
  • was a nice try, but no success. Maybe its because I'm working in a strong connection with an third party ADK and I'm calling many methods out of this ADK. Maybe it does something in the background which "blocks" my layout. I debugged already to prove that, but maybe i have overseen something – Fraggles Dec 18 '13 at 11:11
  • Now I see that it is really weird hahaha! For the solutions I can recommend I suggest you to first add a theme for you manifest file. Second is to try to clean your project. Close your IDE and reopen the project (this solves my dependency problem most of the time in android studio). I can't assure it will solve your problem but who knows? :) – KaHeL Dec 18 '13 at 11:27
  • I guess, its the ADK, so I have to figure out whats "blocking" my layout. thx for all your help until now. – Fraggles Dec 18 '13 at 11:29
  • is it technically possible to "block" all attempts to modify a layout ? – Fraggles Dec 19 '13 at 11:04
  • okay, I got the problem. Its a bit stupid :( I have a print(String) method, which has a setContentView(TextView); -> so sure it overlays the "main" layout. thx for all your answers :) – Fraggles Dec 19 '13 at 11:12

4 Answers4

0

try this code. it works for me.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btn_window_up" />

<Button
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btn_window_up"
    android:text="@string/btn_window_down" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/btn_window_down"
    android:text="sample text here" />

</RelativeLayout>
Yogamurthy
  • 988
  • 15
  • 22
0

try this ..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<Button
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 1" />

<Button
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 2" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your text view goes over here" />

</LinearLayout>

Or like this ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

<Button
    android:layout_weight="1"
    android:id="@+id/btn_window_up"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 1" />

<Button
    android:layout_weight="1"
    android:id="@+id/btn_window_down"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BTN 2" />

</LinearLayout>

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Your text view goes over here" />

</LinearLayout>
AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
0

The easiet way is to use a LinearLayout with an android:orientation="vertical"

Arnaud
  • 509
  • 5
  • 13
0

try its

its perfectly show all content of layout..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/RelativeLayout1"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" >

    <Button
        android:id="@+id/btn_window_up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/btn_window_up" />

    <Button
        android:id="@+id/btn_window_down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/btn_window_up"
        android:text="@string/btn_window_down" />

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_window_down"
        android:layout_marginTop="10dp"
        android:padding="10dp"
        android:textColor="@android:color/black"
        android:background="@android:color/white"
        android:layout_centerHorizontal="true"
        android:text="&quot;Demo ADK V1.0&quot;" />
</RelativeLayout>

  • also no success. I'm trying for nearly 2 days now and I think its a problem with in the ADK I am using. So a problem that I can only solve myself :( – Fraggles Dec 18 '13 at 11:27
  • sorry for the late answer, but I found the problem :) A setContentView = (TextView)... has overridden the main ContentView ... so the Buttons were overlayed by the TextView – Fraggles Jan 07 '14 at 13:56