Transferred from: http://www.cnblogs.com/pswzone/archive/2012/03/10/2389275.html
packagecom.wps.android;
importjava.util.ArrayList;importandroid.app.Activity;importandroid.content.Intent;importandroid.os.Bundle;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.AdapterView.OnItemClickListener;importandroid.widget.ArrayAdapter;importandroid.widget.ListView;publicclassLayouts extends Activity { /** Called when the activity is first created. */ privateListView mylistview; privateArrayList<String> list = newArrayList<String>(); @Override publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mylistview = (ListView)findViewById(R.id.listview); list.add("LinearLayout"); list.add("AbsoluteLayout"); list.add("TableLayout"); list.add("RelativeLayout"); list.add("FrameLayout"); ArrayAdapter<String> myArrayAdapter = newArrayAdapter<String> (this,android.R.layout.simple_list_item_1,list); mylistview.setAdapter(myArrayAdapter); /*mylistview.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_DOWN) { mylistview.setBackgroundColor(Color.BLUE); } return false; } });*/ mylistview.setOnItemClickListener(newOnItemClickListener(){ @Override publicvoidonItemClick(AdapterView<?> arg0, View arg1, intarg2, longarg3) { // TODO Auto-generated method stub if(list.get(arg2).equals("LinearLayout")) { Intent intent = newIntent("com.wps.android.LINEARLAYOUT"); startActivity(intent); } if(list.get(arg2).equals("AbsoluteLayout")) { Intent intent = newIntent("com.wps.android.ABSOLUTELAYOUT"); startActivity(intent); } if(list.get(arg2).equals("TableLayout")) { Intent intent = newIntent("com.wps.android.TABLELAYOUT"); startActivity(intent); } if(list.get(arg2).equals("RelativeLayout")) { Intent intent = newIntent("com.wps.android.RELATIVELAYOUT"); startActivity(intent); } if(list.get(arg2).equals("FrameLayout")) { Intent intent = newIntent("com.wps.android.FRAMELAYOUT"); startActivity(intent); } } }); }}