I want to integrate zxing qr code scanner in my application which is having three tabs in my application.
Currently when my one of the tab bar butto gets pressed at that time I am calling zxing qr code's scann activity but when ever its calling it is showing error like below.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.beepz/com.google.zxing.client.android.CaptureActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
Rather my code is having both tab host control and I have instantiated tab host in my activity call as shown below.
XML File (Capture.xml) :
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
<com.google.zxing.client.android.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/transparent" />
</SurfaceView>
</FrameLayout>
Java File : (CaptureActivity.java)
public final class CaptureActivity extends TabActivity implements
SurfaceHolder.Callback {
private TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.capture);
tabHost = getTabHost();
Intent intent = new Intent().setClass(this, first.class);
TabSpec spec = tabHost.newTabSpec("First Tab").setIndicator("First Tab",getResources().getDrawable(R.drawable.iconinfo)).setContent(intent);
tabHost.addTab(spec);
.
.
.
}
Do I need to change any thing in manifest file or anything else I need to do?
Can any body please help me what should I do?
Thanks In Advance...
At last I solved my problem on my own, the problem was, there was a CaptureActivity.java file in my main project. And problem solved by adding TabHost in the main project's CaptureActivity.java file.
Hopefully It will be helpful to others too.
来源:https://stackoverflow.com/questions/16370670/how-to-integrate-tab-host-with-zxing-qr-code-scanner