The Code is as follows:
Public class GroupActivity extends Activity {
Private List gbList;
// Private MyListAdapter adapter;
Private ItemClickEvent listener;
// Private MyHandler handler;
Private GridView [] gridvs;
//
Private LinearLayout ll_main;
Private ScrollView scll;
Private LinearLayout scll_sub_ll;
Private HorizontalScrollView hls;
Private LinearLayout hls_sub_ll;
Private GridView gv;
Private LinearLayout. LayoutParams ll_pmm;
Private LinearLayout. LayoutParams ll_pmw;
Private LinearLayout. LayoutParams ll_pww;
Private LinearLayout. LayoutParams ll_head_wh;
Private int headViewW = 0, headViewH = 0;
Private TextView TV _type;
Private View headView;
Private LayoutInflater flater;
Private Button bt_back, bt_right;
Private TextView top_title;
Private MyListAdapter [] myAdaps;
Handler hand = new Handler (){
Public void handleMessage (Message msg ){
Switch (msg. what ){
Case 1:
Log. I ("AAA", "case1" + msg. what );
If (null = gbList | gbList. size () <0 ){
Return;
}
Init ();
Break;
Case 2:
SetContentView (ll_main );
Break;
Default:
Break;
}
};
};
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
RequestWindowFeature (Window. FEATURE_INDETERMINATE_PROGRESS );
// SetContentView (R. layout. main );
New Thread (){
@ SuppressLint ("NewApi ")
Public void run (){
GbList = new ArrayList ();
For (int I = 0; I <10; I ++ ){
TeamBean item = new TeamBean ("abc" + I, "123456"
+ I );
Log. I ("AAA", "item =" + item );
GbList. add (item );
}
Message msg = Message. obtain ();
Msg. what = 1;
Hand. sendMessage (msg );
}
}. Start ();
}
Private void init (){
HeadView = getLayoutInflater (). inflate (R. layout. dingbujiemian, null );
HeadView. setBackgroundResource (R. drawable. top_bg );
Bt_back = (Button) headView. findViewById (R. id. zuobianniu );
Bt_back.setVisibility (View. VISIBLE );
Bt_back.setBackgroundResource (R. color. transparent );
Bt_back.setText (getResources (). getString (R. string. fanhui ));
Bt_back.setOnClickListener (new OnClickListener (){
Public void onClick (View v ){
// TODO Auto-generated method stub
Finish ();
}
});
Bt_right = (Button) headView. findViewById (R. id. youbianniu );
Bt_right.setVisibility (View. INVISIBLE );
Top_title = (TextView) headView. findViewById (R. id. zhongjianzifu );
Top_title.setVisibility (View. INVISIBLE );
Ll_pmm = new LinearLayout. LayoutParams (LayoutParams. MATCH_PARENT, LayoutParams. MATCH_PARENT );
Ll_pmw = new LinearLayout. LayoutParams (LayoutParams. MATCH_PARENT, LayoutParams. WRAP_CONTENT );
Ll_pww = new LinearLayout. LayoutParams (LayoutParams. WRAP_CONTENT, LayoutParams. WRAP_CONTENT );
// Int w = View. MeasureSpec. makeMeasureSpec (0, View. MeasureSpec. UNSPECIFIED );
// Int h = View. MeasureSpec. makeMeasureSpec (0, View. MeasureSpec. UNSPECIFIED );
// HeadView. measure (w, h );
// HeadViewW = headView. getMeasuredWidth ();
// HeadViewH = headView. getMeasuredHeight ();
// Ll_head_wh = new LinearLayout. LayoutParams (headViewW, headViewH );
// HeadView. setLayoutParams (ll_head_wh );
Ll_main = new LinearLayout (this );
Ll_main.setOrientation (LinearLayout. VERTICAL );
Ll_main.setBackgroundColor (Color. WHITE );
Ll_main.setLayoutParams (ll_pmm );
Ll_main.addView (headView );
Scll = new ScrollView (this );
Scll. setLayoutParams (ll_pmm );
Scll_sub_ll = new LinearLayout (this );
Scll_sub_ll.setOrientation (LinearLayout. VERTICAL );
Scll_sub_ll.setLayoutParams (ll_pmm );
Int arrs [] = new int [15];
MyAdaps = new MyListAdapter [arrs. length];
For (int I = 0; I <arrs. length; I ++ ){
Hls = new HorizontalScrollView (this );
Hls. setLayoutParams (ll_pmw );
Hls. setBackgroundColor (Color. GRAY );
Hls. setHorizontalScrollBarEnabled (false );
Hls_sub_ll = new LinearLayout (this );
Hls_sub_ll.setOrientation (LinearLayout. HORIZONTAL );
Hls_sub_ll.setLayoutParams (ll_pmw );
Gv = new GridView (this );
Gv. setLayoutParams (ll_pmw );
LayoutParams params = new LayoutParams (gbList. size ()
* (120 + 6), LayoutParams. WRAP_CONTENT );
Gv. setLayoutParams (params );
Gv. setColumnWidth (120 );
Gv. setHorizontalSpacing (6 );
/* Gv. setStretchMode (gv. NO_STRETCH );*/
Gv. setNumColumns (gbList. size ());
MyAdaps [I] = new MyListAdapter (GroupActivity. this );
Listener = new ItemClickEvent ();
If (I = arrs. length-1 ){
} Else {
Gv. setAdapter (myAdaps [I]);
Gv. setOnItemClickListener (listener );
}
Hls_sub_ll.addView (gv );
Hls. addView (hls_sub_ll );
TV _type = new TextView (this );
TV _type.setTextSize (22 );
TV _type.setTextColor (Color. BLACK );
If (I = arrs. length-1 ){
TV _type.setText ("selected friend ");
} Else {
TV _type.setText ("friend" + I );
}
Scll_sub_ll.addView (TV _type );
Scll_sub_ll.addView (hls );
}
Scll. addView (scll_sub_ll );
Ll_main.addView (scll );
Message msg = Message. obtain ();
Msg. what = 2;
Hand. sendMessage (msg );
}
Private class MyListAdapter extends BaseAdapter {
Private final String TAG = "MyListAdapter ";
Private LayoutInflater mInflater;
Private final Context context;
Public MyListAdapter (Context context ){
This. context = context;
MInflater = (LayoutInflater) context
. GetSystemService (Context. LAYOUT_INFLATER_SERVICE );
}
Public int getCount (){
Log. I ("AAA", "gbList. size () =" + gbList. size ());
Return gbList. size ();
}
Public Object getItem (int position ){
Return gbList. get (position );
}
Public long getItemId (int position ){
Return position;
}
@ TargetApi (Build. VERSION_CODES.HONEYCOMB)
@ SuppressLint ("NewApi ")
Public View getView (int position, View convertView, ViewGroup parent ){
Log. I ("AAA", "position =" + position );
TeamBean item = gbList. get (position );
Log. I ("AAA", "getView (), item =" + item );
CellHolder cellHolder;
If (convertView = null ){
CellHolder = new CellHolder ();
ConvertView = mInflater. inflate (R. layout. team_item, null );
CellHolder. ivIcon = (ImageView) convertView
. FindViewById (R. id. ivIcon );
CellHolder. name = (TextView) convertView
. FindViewById (R. id. name );
ConvertView. setTag (cellHolder );
} Else {
CellHolder = (CellHolder) convertView. getTag ();
}
CellHolder. ivIcon. setImageResource (R. drawable. icos5 );
CellHolder. name. setText (item. getName ());
CellHolder. name. setTextSize (12 );
Return convertView;
}
}
Private class CellHolder {
ImageView ivIcon;
TextView name;
}
Private class ItemClickEvent implements OnItemClickListener {
Public void onItemClick (AdapterView parent, View view, int position,
Long id ){
Log. I ("item", "parent =" + parent + ", view =" + view + ", position =" + position );
}
}
}