Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Tab Tutorial Trouble
    primarykey
    data
    text
    <h2>PROBLEM SOLVED!!</h2> <p><strong>I just found my mistakes, after looking through the debugger over and over again, but anyway, thanks everyone!!</strong></p> <p>Hi there, I am very new to Android and was working through some tutorials. Now I got stuck at the Tab tutorial. The code seems to be fine at first glance as I am not getting any errors, but when I try to run the app on the emulator it always crashes and I get an "application stopped unexpectedly" error message. </p> <p>I already tried what was said in the discussion about the <a href="http://www.anddev.org/problem_with_android_tab_layout_tutorial-t10722.html" rel="nofollow noreferrer">tab layout problem</a>, but the changes I made didn't help with the error. If someone can help me with that, that would absolutely great. If you would like to see the code, just tell me if I should post or send it. </p> <p>Thank u in advance.</p> <p>This is my code for the <strong>Manifest.xml</strong> file because I am not sure, if I have done something wrong there:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mobilevideoeditor.moved" android:versionCode="1" android:versionName="1.0"&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".GalleryView" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;activity android:name=".ShareGalleryView" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"&gt; &lt;/activity&gt; &lt;activity android:name=".EditGalleryView" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"&gt; &lt;/activity&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>This is the <strong>GalleryView.java</strong> file: </p> <pre><code>package com.mobilevideoeditor.moved; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost; public class GalleryView extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Reusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, EditGalleryView.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("edit").setIndicator("Edit", res.getDrawable(R.drawable.ic_tab_edit)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, ShareGalleryView.class); spec = tabHost.newTabSpec("share").setIndicator("Share", res.getDrawable(R.drawable.ic_tab_share)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); } } </code></pre> <p>Here is the code for the <strong>main.xml</strong>: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>The code for the <strong>EditGalleryView.java</strong> and the <strong>ShareGalleryView.java</strong>: </p> <pre><code>package com.mobilevideoeditor.moved; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ShareGalleryView extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textview = new TextView(this); textview.setText("This is the Share tab!"); setContentView(textview); } } </code></pre> <p>And finally the code for the <strong>ic_tab_share.xml</strong> and the <strong>ic_tab_edit.xml</strong>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;!-- When selected, use ic_tab_share (grey icon) --&gt; &lt;item android:drawable="@drawable/ic_tab_share" android:state_selected="true" /&gt; &lt;!-- When not selected, use ic_tab_share_unselected (white icon)--&gt; &lt;item android:drawable="@drawable/ic_tab_share_unselected" /&gt; &lt;/selector&gt; </code></pre> <p>Thanks again :) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload