1

我的主菜单中有一个子菜单,其中有一个打开列表视图活动的按钮,即使在代码中没有检测到错误,它仍然在单击时崩溃。从创建自定义数组到使用自动生成的通用列表,我尝试了一些方法。我确定这是布局的问题...

带有应创建列表的按钮(abbutton)的活动:

package org.myscores.www;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.view.View.OnClickListener;
public class sundayopen extends Activity implements OnClickListener {

    @Override
    protected void onCreate(Bundle myscores) {
         super.onCreate(myscores);
         setContentView(R.layout.sundayopen);
         ImageButton hb1 = (ImageButton) findViewById(R.id.homebutton1);
         ImageButton sbc = (ImageButton) findViewById(R.id.satlidopen);
         ImageButton ab = (ImageButton) findViewById(R.id.abbutton);
         sbc.setOnClickListener(this);
         hb1.setOnClickListener(this);
         ab.setOnClickListener(this);
    }


         public void onClick(View v){
             switch (v.getId()) {
             case R.id.homebutton1:
                startActivity(new Intent(this, MainActivity.class));
                 break;
             case R.id.satlidopen:
                startActivity(new Intent(this,stat.class));
                break;
             case R.id.abbutton:
                 startActivity(new Intent(this, ablist.class));

             }
         }
}

xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/scoreback" >

    <ImageView
        android:id="@+id/scorebox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="63dp"
        android:contentDescription="@string/scorebox"
        android:src="@drawable/scorebox" />

    <ImageButton
        android:id="@+id/satlid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/pillboxm"
        android:layout_alignRight="@+id/pillboxm"
        android:background="@android:color/transparent"
        android:contentDescription="@string/satlid"
        android:src="@drawable/slid" />

    <ImageButton
        android:id="@+id/frilid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thulid"
        android:layout_toLeftOf="@+id/satlid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/frilid"
        android:src="@drawable/flid" />

    <ImageButton
        android:id="@+id/thulid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/pillboxm"
        android:layout_toLeftOf="@+id/frilid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/thulid"
        android:src="@drawable/tlid" />

    <ImageButton
        android:id="@+id/homebutton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="11dp"
        android:background="@android:color/transparent"
        android:contentDescription="@string/homebutton"
        android:src="@drawable/homebut1" />

    <ImageButton
        android:id="@+id/wedlid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thulid"
        android:layout_toLeftOf="@+id/thulid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/wedlid"
        android:src="@drawable/wlid" />

    <ImageButton
        android:id="@+id/tuelid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/pillboxm"
        android:layout_toLeftOf="@+id/wedlid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/tuelid"
        android:src="@drawable/tlid" />

    <ImageButton
        android:id="@+id/monlid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/pillboxm"
        android:layout_toLeftOf="@+id/tuelid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/monlid"
        android:src="@drawable/mlid" />

    <ImageButton
        android:id="@+id/adbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/abbutton"
        android:background="@android:color/transparent"
        android:contentDescription="@string/adbutton"
        android:src="@drawable/adbutton" />

    <ImageButton
        android:id="@+id/abbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/cobutton"
        android:layout_alignParentRight="true"
        android:background="@android:color/transparent"
        android:contentDescription="@string/abbutton"
        android:src="@drawable/antibiotic_buton" />

    <ImageButton
        android:id="@+id/bppressure"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/monlid"
        android:layout_alignTop="@+id/adbutton"
        android:background="@android:color/transparent"
        android:contentDescription="@string/bpbutton"
        android:src="@drawable/bpbutton" />

    <ImageButton
        android:id="@+id/satlidopen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/monlid"
        android:layout_toLeftOf="@+id/monlid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/satlidopen"
        android:src="@drawable/satlidopen" />

    <ImageButton
        android:id="@+id/cobutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/satlidopen"
        android:layout_marginBottom="133dp"
        android:layout_toRightOf="@+id/wedlid"
        android:background="@android:color/transparent"
        android:contentDescription="@string/cobutton"
        android:src="@drawable/cobutton" />

  </RelativeLayout>

列表视图 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"
     >
     <ListView  
         android:id="@android:id/scre"
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         />
     <TextView android:id="@android:id/empty"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Empty set"
         />
 </LinearLayout>

列表视图 java:

package org.myscores.www;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class screj extends ListActivity {
        String[] listItems = {"week", "month", 
                              "yead", "day"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pointlist);
    setListAdapter(new ArrayAdapter(this, 
         android.R.layout.simple_list_item_1, listItems));
}
}

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="org.myscores.www"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15"/> 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:enabled="true">

    <activity
        android:name="org.myscores.www.Splashscreen"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar">    
   <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />        
   </intent-filter>
   </activity>
   <activity   
        android:name="org.myscores.www.Splashscreen2"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar">
    <intent-filter>       
    </intent-filter>
    </activity>                  
    <activity
        android:name="org.myscores.www.MainActivity"
        android:label="@string/app_name"/>
     <activity      
        android:name="org.myscores.www.difference"
        android:label="@string/app_name"/>   
      <activity          
        android:name="org.iimed.www.scoreboard"
        android:label="@string/app_name"/>   
    <activity
        android:name="org.myscores.www.sundayopen"
        android:label="@string/app_name"/>
    <activity
        android:name="org.myscores.www.pointlist"
        android:label="@string/app_name"/>

     </application>
    </manifest>

谢谢你的耐心。

4

2 回答 2

0

您的清单活动未在清单中声明。例如,您必须在添加 MainActivity 时添加它。

<activity
            android:name="org.myscores.www.ablist"
             android:label="@string/app_name"/>
于 2013-10-22T09:37:55.773 回答
0

带有应创建列表的按钮(abbutton)的活动:

我相信您想在单击时开始列表活动abbutton

改变这个

case R.id.abbutton:
      startActivity(new Intent(this, ablist.class));

case R.id.abbutton:
       startActivity(new Intent(this, screj.class));

因为

public class screj extends ListActivity { 
// activity name is scresj not ablist

并确保你在清单中有这个

 <activity
    android:name="org.myscores.www.screj"
    android:label="@string/app_name">
 </activity>   

也用于统计活动

 <activity
    android:name="org.myscores.www.stat"
    android:label="@string/app_name">
 </activity>   

编辑 :

ListActivity具有默认布局,由屏幕中央的单个全屏列表组成。但是,如果您愿意,您可以通过在 onCreate() 中使用 setContentView() 设置您自己的视图布局来自定义屏幕布局。为此,您自己的视图必须包含一个带有 id 的 ListView 对象"@android:id/list"(或列表,如果它在代码中)

所以你需要在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"
     >
     <ListView android:id="@android:id/list"  // id must be @android:id/list
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         />
     <TextView android:id="@android:id/empty"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Empty set"
         />
 </LinearLayout>

总是让类名以大写开头,如Screj

不确定,但你有。我相信您在. 所以改为<activity
android:name="org.iimed.www.scoreboard"
scoreboardorg.myscores.www package<activity
android:name="org.myscores.www.scoreboard"

于 2013-10-22T09:38:04.087 回答