我正在尝试在每个 1 个列表项中创建一个包含 2 个项目的 ListView,但它似乎不起作用,它强制关闭,请帮忙?
这是课程
package egypt.interfaceAct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import egypt.database.EgyptDataSource;
import egypt.database.MySQLiteHelper;
import egypt.database.TouringPrograms;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ProgramsList2 extends Activity{
EgyptDataSource datasource;
MySQLiteHelper sqlHelper;
//ArrayAdapter<TouringPrograms> touringProgramAdapter;
final String ACTIVITY_KEY = "activity";
final String TIME_KEY = "time";
ListView list;
ArrayList<Map<String, String>> al;
Map<String, String> map;
SimpleAdapter sa;
String[] from = {ACTIVITY_KEY, TIME_KEY};
int[] to = {R.id.tableTextID, R.id.tableText2ID};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.programsmain);
datasource = new EgyptDataSource(this);
datasource.open();
list = (ListView) findViewById(R.id.programsMainList);
al = new ArrayList<Map<String,String>>();
Bundle programNum = getIntent().getExtras();
final String progNum = programNum.getString("ProgNum");
final String dayNum = programNum.getString("DayNum");
List<TouringPrograms> Activityvalues = datasource.getTouringPrograms(progNum, dayNum);
List<TouringPrograms> Timevalues = datasource.getTouringProgramsStartTime(progNum, dayNum);
Object[] ActivityArray = Activityvalues.toArray();
Object[] TimeArray = Timevalues.toArray();
for (int i = 0; i < Activityvalues.size(); i++) {
map = new HashMap<String, String>();
map.put(ACTIVITY_KEY, ActivityArray[i].toString());
map.put(TIME_KEY, TimeArray[i].toString());
al.add(map);
}
sa = new SimpleAdapter(this, al, R.layout.programstable, from, to);
list.setAdapter(sa);
}
}
这是其中只有 ListView 的主要布局
<?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="@+id/programsMainList"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
这是解释 ListView 中每个项目的表格布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tableTextID"
/>
</TableRow>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/tableText2ID"
/>
</TableRow>
</LinearLayout>
有人可以帮帮我吗!我不知道出了什么问题,我一遍又一遍地搜索,我无法弄清楚出了什么问题!
这是 LogCat
06-22 22:57:42.192: E/AndroidRuntime(306): FATAL EXCEPTION: main
06-22 22:57:42.192: E/AndroidRuntime(306): java.lang.RuntimeException: Binary XML file line #7: You must supply a layout_width attribute.
06-22 22:57:42.192: E/AndroidRuntime(306): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3592)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:3672)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1395)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1321)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:45)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:121)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.ListView.makeAndAddView(ListView.java:1727)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.ListView.fillDown(ListView.java:652)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.ListView.fillFromTop(ListView.java:709)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.ListView.layoutChildren(ListView.java:1580)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.AbsListView.onLayout(AbsListView.java:1147)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.View.layout(View.java:7035)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.View.layout(View.java:7035)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.View.layout(View.java:7035)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.View.layout(View.java:7035)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.View.layout(View.java:7035)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.os.Looper.loop(Looper.java:123)
06-22 22:57:42.192: E/AndroidRuntime(306): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-22 22:57:42.192: E/AndroidRuntime(306): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 22:57:42.192: E/AndroidRuntime(306): at java.lang.reflect.Method.invoke(Method.java:521)
06-22 22:57:42.192: E/AndroidRuntime(306): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-22 22:57:42.192: E/AndroidRuntime(306): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-22 22:57:42.192: E/AndroidRuntime(306): at dalvik.system.NativeStart.main(Native Method)