我的主菜单中有一个子菜单,其中有一个打开listview活动的按钮,即使代码中没有检测到错误,它仍然会在点击时崩溃。我尝试了一些从创建自定义数组到使用自动生成的通用列表的东西。我确定布局有问题......
带有应创建列表的按钮(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>
listview 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>
listview 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>
感谢您的耐心等待。
答案 0 :(得分:0)
您的清单活动未在清单中声明。例如,您必须在添加MainActivity时添加它。
<activity
android:name="org.myscores.www.ablist"
android:label="@string/app_name"/>
答案 1 :(得分: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为"@android:id/list"
的ListView对象(如果它在代码中则列出)
所以你需要在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"scoreboard
中有一个名为org.myscores.www package
的活动。因此改为<activity
android:name="org.myscores.www.scoreboard"