1. 程式人生 > >Activity裡獲取Adapter控制元件值

Activity裡獲取Adapter控制元件值

大笑大笑好記性不如爛筆頭;

ListView list= (ListView)findViewById(R.id.list);//獲得listview

for (int i = 0; i < list.getChildCount(); i++) {
     LinearLayout layout = (LinearLayout)list.getChildAt(i);// 獲得子item的layout
     EditText et = (EditText) layout.findViewById(R.id.et);// 從layout中獲得控制元件,根據其id
// EditText et = (EditText) layout.getChildAt(1)//或者根據位置,在這我假設TextView在前,EditText在後
     
     System.out.println("the text of "+i+"'s EditText:----------->"+et.getText());
}


//第二種

 listViewAdpret.setOnItemClickListener(new BDListViewAdpret.OnItemClickListener() {
                            @Override
                            public void onItemClick(View view, int position) {
                                try {
                                    djrx = 0;
                                    //left_listView是佈局檔案控制元件
                                    RecyclerView  mGroup= (RecyclerView) left_listView.getChildAt(position).findViewById(R.id.rl_group);
                                    mGroup.setVisibility(View.VISIBLE);
                                    sectionedAdapter.setList(haoshihomebean.goods.get(position).erji);
//                                    sectionedAdapter.notifyDataSetChanged();
                                    listViewAdpret.setSelectedPosition(position);
                                    listViewAdpret.notifyDataSetChanged();


                                } catch (Exception e) {
                                }
                            }
                        });