2013-12-18 172 views
2

我有Android項目,我必須更改最後一個exxpanded組(它將崩潰)的佈局和被點擊的組。 onGroupClick方法我有:可擴展列表視圖android更改佈局點擊

int cnt=list.getChildCount();      
       //set layout to all groups (for closed group) 
       for(int i = 0; i < cnt; i`enter code here`++){ 
        View group = adapter.getGroupView(i, false, 
          null, list); 
         LinearLayout childLayout = (LinearLayout) group.findViewById(R.id.newsLayout);       childLayout.setBackgroundResource(R.layout.group_layout_shape);    
       } 
       // set layout of clicked group 
       LinearLayout groupLayout = (LinearLayout) v.findViewById(R.id.newsLayout); 
       groupLayout.setBackgroundResource(R.layout.group_layout_opened_shape);`enter code here` 

它改變點擊組的佈局(這將擴大),但不改變組的佈局,即colapses :(可ayone幫我

回答

0

你不應該使用這個方法,因爲它僅用於圖片,顏色,佈局要使用打氣筒,其中有一個非常有趣的方法

充氣(R.layout.childLayout,ParentView,真);

,你把第一你想膨脹的層,第二層 - 一個paren將包含孩子和第三個 - 一個布爾變量必須是真實的膨脹保持。

實施例的活動:

public class MainActivity extends ActionBarActivity { 

LayoutInflater inflater; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); 
    RelativeLayout parentView= (RelativeLayout) findViewById(R.id.mainLayout); 
    View v = (View) inflater.inflate(R.layout.child_layout, parentView, true); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

}