我正在用 xml 文件进行动态的扩展列表视图, 但是当我在列表中没有内容的布局中装入时, 我崩溃了 。 以下是我的代码 :
密码列表活动。
public class PasswordListingActivity extends ExpandableListActivity {
Button b_addPwd;
ExpandableListView elv_pwdList;
List<Map<String, String>> ServiceList = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> DetailList = new ArrayList<List<Map<String, String>>>();
ExpandableListAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.passwordlisting);
b_addPwd = (Button)findViewById(R.id.b_addpwd);
elv_pwdList = (ExpandableListView)findViewById(R.id.password_list);
b_addPwd.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setClass(PasswordListingActivity.this, AddPasswordActivity.class);
startActivityForResult(intent, 0);
}
});
adapter = new SimpleExpandableListAdapter(
this,
ServiceList,
android.R.layout.simple_expandable_list_item_1,
new String[] {"SERVICE"},
null,
DetailList,
android.R.layout.simple_expandable_list_item_2,
new String[] {"TITLE", "CONTENT",},
null
);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
switch (resultCode){
case RESULT_OK:
Bundle bundleR = data.getExtras();
Map<String, String> ServiceGroupMap = new HashMap<String, String>();
ServiceGroupMap.put("SERVICE", bundleR.getString("service"));
ServiceList.add(ServiceGroupMap);
List<Map<String, String>> DetailGroup = new ArrayList<Map<String, String>>();
Map<String, String> DetailGroupMap = new HashMap<String, String>();
DetailGroupMap.put("TITLE", "User Name: ");
DetailGroupMap.put("CONTENT", bundleR.getString("username"));
DetailGroup.add(DetailGroupMap);
DetailGroupMap.put("TITLE", "Password: ");
DetailGroupMap.put("CONTENT", bundleR.getString("password"));
DetailGroup.add(DetailGroupMap);
DetailList.add(DetailGroup);
break;
default:
break;
}
}
密码列表. xml :
<?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:background="@color/white"
android:orientation="vertical" >
<TextView
android:id="@+id/password_listing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="@string/app_name"
android:textColor="@color/black"
android:textSize="20dip"
android:textStyle="bold" />
<Button
android:id="@+id/b_add_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/add" />
<ExpandableListView
android:id="@+id/password_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
错误代码 :
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
代码有什么问题?