2012-02-08 63 views
2

我正在使用片段和兼容性支持構建選項卡式應用程序。Android - 使用按鈕控制片段內的列表視圖

在其中一個選項卡中,我想要一個listview。在這個相同的選項卡中,我必須按鈕來更改列表視圖項(可以說每個按鈕都有一個分配的字符串數組)。 我不知道如何做到這一點。我已經構建了按鈕的佈局和clicklisteners(這些工作是因爲我用吐司消息測試過)。

你能給我一個提示嗎?我會在哪裏放置listview代碼?在OnClick上? OnCreateView?

對不起,我沒有太多的android經驗。

這是我的片段代碼。

public class TabFragment6 extends ListFragment { 
/** (non-Javadoc) 
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) 
*/ 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    if (container == null) { 
     // We have different layouts, and in one of them this 
     // fragment's containing frame doesn't exist. The fragment 
     // may still be created from its saved state, but there is 
     // no reason to try to create its view hierarchy because it 
     // won't be displayed. Note this is not needed -- we could 
     // just run the code below, where we would create and return 
     // the view hierarchy; it would just never be used. 
     return null; 
    } 



    LinearLayout theLayout = (LinearLayout)inflater.inflate(R.layout.tab_frag6_layout, container, false); 

    // Register for the Button.OnClick event GUITARRA 
    Button bShopGuit = (Button)theLayout.findViewById(R.id.buttonshopguit); 
    bShopGuit.setOnClickListener(new View.OnClickListener() {   //abre setonclicklistener(
     @Override 
     public void onClick(View v) { 
      Toast.makeText(TabFragment6.this.getActivity(), "GUITAR button clicked", Toast.LENGTH_LONG).show(); 

     } 
    });                 //fecha) 

    // Register for the Button.OnClick event BAIXO 
      Button bShopBass = (Button)theLayout.findViewById(R.id.buttonshopbass); 
      bShopBass.setOnClickListener(new View.OnClickListener() {   //abre setonclicklistener(
       @Override 
       public void onClick(View v) { 
        Toast.makeText(TabFragment6.this.getActivity(), "BASS button clicked", Toast.LENGTH_LONG).show(); 
       } 
      });                 //fecha) 

    return theLayout; 
} 

}

回答