比如里面的tabs3.java,代码如下,怎么知道它调用的是哪个layout?:/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */package com.example.android.apis.view;import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.content.Intent;/**
 * An example of tab content that launches an activity via {@link android.widget.TabHost.TabSpec#setContent(android.content.Intent)}
 */
public class Tabs3 extends TabActivity {    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        final TabHost tabHost = getTabHost();        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("list")
                .setContent(new Intent(this, List1.class)));        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("photo list")
                .setContent(new Intent(this, List8.class)));
        
        // This tab sets the intent flag so that it is recreated each time
        // the tab is clicked.
        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("destroy")
                .setContent(new Intent(this, Controls2.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
    }
}

解决方案 »

  1.   

    注意以下地方
    .setContent(new Intent(this, List1.class)));.setContent(new Intent(this, List8.class)));.setContent(new Intent(this, Controls2.class)
    对应了 List1 List8 Controls2 三个类,进去后查看对应的oncreat()函数,里面可以找到设置布局文件的地方 例如 R.layout.list_8,对应的就是 res/layout/list_8.xml
      

  2.   


    就是没有对应的List8.xml存在。不过目前的问题已经解决了,我没加Activity。上面这个例子,它应该用的是一些内置的格式,我没把list.class的代码贴出来,不好意思。
      

  3.   

    把代码贴出来注释说了在android.R.layout.simple_list_item_2.xml中有相关定义,但是我在项目里都没找到这个xml文件在哪。
    /*
     * Copyright (C) 2007 The Android Open Source Project
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */package com.example.android.apis.view;
    import android.app.ListActivity;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.provider.Contacts.Phones;
    import android.widget.ListAdapter;
    import android.widget.SimpleCursorAdapter; /**
     * A list view example where the 
     * data comes from a cursor, and a
     * SimpleCursorListAdapter is used to map each item to a two-line
     * display.
     */
    public class List3 extends ListActivity {
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);        // Get a cursor with all phones
            Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, null);
            startManagingCursor(c);
            
            // Map Cursor columns to views defined in simple_list_item_2.xml
            ListAdapter adapter = new SimpleCursorAdapter(this,
                    android.R.layout.simple_list_item_2, c, 
                            new String[] { Phones.NAME, Phones.NUMBER }, 
                            new int[] { android.R.id.text1, android.R.id.text2 });
            setListAdapter(adapter);
        }
      
    }
      

  4.   


    我没说清楚,我用的是源码开发,所以有Android的源码,ApiDemos是Android的内置应用,所以SDK上可能看不到其源码。如果你想学习ApiDemos的程序最好还是下载全部的源码吧。
    以下是list_8.xml的内容<?xml version="1.0" encoding="utf-8"?>
    <!-- Copyright (C) 2007 The Android Open Source Project     Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at
      
              http://www.apache.org/licenses/LICENSE-2.0
      
         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
    --><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent" 
        android:layout_height="match_parent">
        
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent" 
            android:layout_height="wrap_content">
            
            <Button android:id="@+id/add"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:text="@string/list_8_new_photo"/>
                
            <Button android:id="@+id/clear"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:text="@string/list_8_clear_photos"/>
                
        </LinearLayout>
        
        <!-- The frame layout is here since we will be showing either
        the empty view or the list view.  -->
        <FrameLayout
            android:layout_width="match_parent" 
            android:layout_height="0dip"
            android:layout_weight="1" >
            <!-- Here is the list. Since we are using a ListActivity, we
                 have to call it "@android:id/list" so ListActivity will
                 find it -->
            <ListView android:id="@android:id/list"
                android:layout_width="match_parent" 
                android:layout_height="match_parent"
                android:drawSelectorOnTop="false"/>
            
            <!-- Here is the view to show if the list is emtpy -->
            <TextView android:id="@+id/empty"
                android:layout_width="match_parent" 
                android:layout_height="match_parent"
                android:text="@string/list_8_no_photos"/>
                
        </FrameLayout>
            
    </LinearLayout>
      

  5.   

    但是我自己做的,也没有xml,也达到效果了,这是怎么回事啊?我就加了个activity。是不是因为代码里有红色那一句,那个我看应该是内置的格式:
    ListAdapter adapter = new SimpleCursorAdapter(this,
                    android.R.layout.simple_list_item_2, c, 
                            new String[] { Phones.NAME, Phones.NUMBER }, 
                            new int[] { android.R.id.text1, android.R.id.text2 });
            setListAdapter(adapter);
      

  6.   

    首先按住Ctrl 然后用鼠标对着 android.R.layout.simple_list_item_2 或者  的 simple_list_item_2。然后出现选项 点击  Open Declaration in layout/xx试试!。
      

  7.   


    这样是可以看到这个xml的内容了。