我正在使用Fragments和兼容性支持构建标签式应用程序。
在其中一个标签中,我想要一个列表视图。在这个相同的选项卡中,我必须按钮,这将更改listview项目(假设每个按钮将分配一个字符串数组)。 我不知道怎么做。我已经为按钮构建了布局和clicklisteners(这是因为我用toast消息测试了它)。
你能给我一个暗示吗?我在哪里放下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;
}
}
答案 0 :(得分:0)
???
首先你有片段。在其中你有ListFragment与适配器。在我的项目中,我使用AsyncTask来处理数据,在其中你可以更新列表。 cource适配器执行此操作,您必须通知它有关数据更改。
这会帮助你How to update listview after calling Asynctask to call webservice,我想,