2013-05-04 83 views
2

我想在我的应用程序中集成zxing qr代码扫描器,在我的应用程序中有三个选项卡。如何将tab主机与zxing qr代码扫描器集成?

当前,当我的标签栏butto被按下的时候,我正在调用zxing qr代码的scann活动,但是当它调用它显示如下所示的错误时。

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' 

而是我的码是具有两个选项卡的主机控制和我在活动呼叫实例标签主机如下所示。

XML文件(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文件:(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); 
    . 
    . 
    . 

} 

我是否需要更改清单文件或任何什么东西否则我需要做?

任何机构请帮我,我该怎么办?

在此先感谢...

回答

1

最后我解决我自己我的问题,问题是,有在我的主要项目CaptureActivity.java文件。通过在主项目的CaptureActivity.java文件中添加TabHost解决了问题。

希望这对其他人也有帮助。