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