Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 布局问题_Android_Xml_Xml Layout - Fatal编程技术网

Android 布局问题

Android 布局问题,android,xml,xml-layout,Android,Xml,Xml Layout,我正在尝试制作一个有固定头球的联赛表格。。。我以前发过帖子并得到了建议,但我仍然有一些问题!我相信这只是一个小问题,是造成我的问题 以下是主页的代码: public class tab_1 extends ListActivity { public int a = Football_appActivity.league; /** Called when the activity is first created. */ @Override public voi

我正在尝试制作一个有固定头球的联赛表格。。。我以前发过帖子并得到了建议,但我仍然有一些问题!我相信这只是一个小问题,是造成我的问题

以下是主页的代码:

public class tab_1 extends ListActivity {

    public int a = Football_appActivity.league;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listplaceholder);
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        if(a==1){
            String xml = XMLfunctions.getXML_prem_table();
            Document doc = XMLfunctions.XMLfromString(xml);
            int numResults = XMLfunctions.numResults(doc);

            if((numResults <= 0)){
                Toast.makeText(tab_1.this, "League Table", Toast.LENGTH_LONG).show();
                finish();
            }

            NodeList nodes = doc.getElementsByTagName("team");
            setContentView(R.layout.table_header);

            for (int i = 0; i < nodes.getLength(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();

                Element e = (Element)nodes.item(i);
                map.put("id", XMLfunctions.getValue(e, "id"));
                map.put("name", "" + XMLfunctions.getValue(e, "name"));
                map.put("played", "" + XMLfunctions.getValue(e, "played"));
                map.put("won", "" + XMLfunctions.getValue(e, "won"));
                map.put("drawn", "" + XMLfunctions.getValue(e, "drawn"));
                map.put("lost", "" + XMLfunctions.getValue(e, "lost"));
                map.put("points", "" + XMLfunctions.getValue(e, "points"));
                mylist.add(map);
            }

            ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main_tab, 
                    new String[] { "name", "played", "won", "drawn", "lost", "points"}, 
                    new int[] { R.id.item_title, R.id.item_played, R.id.item_won,
                    R.id.item_drawn, R.id.item_lost, R.id.item_points});
            setListAdapter(adapter);

            final ListView lv = getListView();
            lv.setTextFilterEnabled(true); 
            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    @SuppressWarnings("unchecked")
                    HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
                    Toast.makeText(tab_1.this, o.get("name") + " have Won '" + o.get("won") + "' games, and are currently on '" + o.get("points") + "' points!", Toast.LENGTH_LONG).show(); 
                }
            });
        }
tableheader.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="7dp">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1"
    android:id="@+id/table_header">
    <TableRow>
    <TextView 
        android:text="Name"
        android:id="@+id/team_title">
        </TextView>
    <TextView android:text="P "
        android:gravity="right"
        android:id="@+id/team_played">
    </TextView>
    <TextView android:text="W"
        android:id="@+id/team_won">
    </TextView>
    <TextView android:text="D"
        android:id="@+id/team_drawn">
    </TextView>
    <TextView android:text="L"
        android:id="@+id/team_lost">
    </TextView>
    <TextView android:text="P"
        android:id="@+id/team_points">
    </TextView>
  </TableRow>
  </TableLayout>

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawSelectorOnTop="false" />
   </LinearLayout>

main_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="7dp"
    >  

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1"
    android:id="@+id/table">
    <TableRow>
        <TextView  
            android:text=""
            android:id="@+id/item_title"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:padding="2dp"
            android:textSize="20dp" />
            <TextView  
            android:id="@+id/item_played"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:gravity="right" 
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_won"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_drawn"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_lost"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_points"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            </TableRow>
            </TableLayout>

</LinearLayout>


谢谢你的帮助

首先,您不能像这样更改布局文件(SetContentView()),错误在于您在其他文件中声明的id是@+id/list,而在listpocholder.xml文件中的id是@+id/android:list,因此它自然会导致错误,所以请首先使用相同名称的两个id。最后,我建议不要使用两个布局xml文件来保存活动,您必须仅使用单个xml来显示活动。

请提供日志,以便我们知道您在哪里出错OK。。所以有一长串的错误。。。但这是我认为导致所有问题的第一个错误:04-16 10:52:13.106:E/AndroidRuntime(339):java.lang.RuntimeException:无法启动活动组件信息{com.julian.football\u app/com.julian.football\u app.tab\u 1}:java.lang.RuntimeException:您的内容必须有一个ListView,其id属性为“android.R.id.list”是布局文件tableheader.xml或table_header.xmlwell的名称,以@mak_Just4any为准,我已调整了所有id,使它们的格式都相同。。。只有一个xml文件的问题是,当它创建listadapter时,您必须设置布局。所以如果我把所有的标题放在这个布局中,它会循环。。e、 g:球队P W L D P阿森纳1队P W L D P曼联1 1如果你的问题仍然没有解决,那么上传所有红色的logcat行。。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="7dp"
    >  

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1"
    android:id="@+id/table">
    <TableRow>
        <TextView  
            android:text=""
            android:id="@+id/item_title"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:padding="2dp"
            android:textSize="20dp" />
            <TextView  
            android:id="@+id/item_played"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:gravity="right" 
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_won"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_drawn"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_lost"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            <TextView  
            android:id="@+id/item_points"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:textSize="13dp" />
            </TableRow>
            </TableLayout>

</LinearLayout>