对着视频中写了一个expandablelist,到错了求教
一个小部分:跳转页面
if(msg.arg1==100){
String facterstr = text_02.getText().toString();
Intent intent = new Intent();
intent.putExtra("name",facterstr);
intent.setClass(denglu.this,main.class);
denglu.this.startActivity(intent);
}
Main的代码:
public class main extends ExpandableListActivity{
TextView text_01;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text_01 = (TextView)findViewById(R.id.text);
Intent intent = getIntent();
String fcterone = intent.getStringExtra("name");
text_01.setText(fcterone);
List<Map<String,String>> groups = new ArrayList<Map<String,String>>();
Map<String,String> group1= new HashMap<String,String>();
group1.put("group","我的家人" );
Map<String,String> group2= new HashMap<String,String>();
group2.put("group","朋友" );
groups.add(group1);
groups.add(group2);
List<Map<String,String>> child1 = new ArrayList<Map<String,String>>();
Map<String,String> child1Data1 = new HashMap<String,String>();
child1Data1.put("child","张珊");
child1.add(child1Data1);
Map<String,String> child1Data2 = new HashMap<String,String>();
child1Data2.put("child","李斯");
child1.add(child1Data2);
List<Map<String,String>> child2 = new ArrayList<Map<String,String>>();
Map<String,String> child2Data1 = new HashMap<String,String>();
child2Data1.put("child","张珊");
child2.add(child2Data1);
Map<String,String> child2Data2 = new HashMap<String,String>();
child2Data2.put("child","李斯");
List<List<Map<String,String>>> childs = new ArrayList<List<Map<String,String>>>();
child2.add(child2Data2);
childs.add(child1);
childs.add(child2);
SimpleExpandableListAdapter sela = new SimpleExpandableListAdapter(this, groups,R.layout.group, new String[]{"group"},new int[]{R.id.groupTo}, childs, R.layout.child, new String[]{"child"},new int[]{R.id.childTo});
setListAdapter(sela);
}
}
Main的xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.example.helper.main"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="81dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="104dp"
android:paddingTop="0dp"
android:layout_height="78dp"
android:src="@drawable/touxiang" />
<TextView
android:textSize="10pt"
android:layout_width="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="15dp"
android:layout_height="wrap_content"
android:id="@+id/text"
android:text="@string/boy"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:orientation="vertical"
android:layout_weight="6">
<ExpandableListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
<TextView
android:id="@+id/text_003"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"/>
</LinearLayout>
</LinearLayout>
我一共写了三个activity,可以编译成功但是当点击按钮跳转到第三个activity的时候程序蹦了。