标签:
源码
public class MainActivity extends AppCompatActivity {
final Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//条目
final Map<String,Class> activities = new LinkedHashMap<String,Class>();
activities.put("WebView", WebViewActivity.class);
//ListView
ListView listView = (ListView)this.findViewById(R.id.listView);
final String[] keies_Title = activities.keySet().toArray(new String[activities.size()]);
ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,keies_Title);//新建适配器对象
listView.setAdapter(arrayAdapter);//适配
//事件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){//点击事件
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(context,activities.get(keies_Title[position]));
startActivity(intent);
}
});
}
}
布局文件
<?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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.cz.czapp.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView">
</ListView>
</RelativeLayout>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
标签:
原文地址:http://www.cnblogs.com/cz2012/p/5811301.html