gpt4 book ai didi

Android - 使用按钮控制 fragment 内的 ListView

转载 作者:行者123 更新时间:2023-11-29 14:01:42 25 4
gpt4 key购买 nike

我正在使用 fragment 和兼容性支持构建一个选项卡式应用程序。

在其中一个选项卡中,我想要一个 ListView 。在同一个选项卡中,我必须按下按钮来更改 ListView 项(可以说每个按钮都会分配一个字符串数组)。我不知道该怎么做。我已经为按钮构建了布局和点击监听器(它们可以正常工作,因为我用 toast 消息对其进行了测试)。

你能给我一个提示吗?我会将 ListView 代码放在哪里?在 OnClick 上?在 OnCreateView 上?

抱歉,我对 android 没有太多经验。

这是我的 fragment 代码。

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;
}

最佳答案

???

首先你有 fragment 。其中有带适配器的 ListFragment。在我的项目中,我使用 AsyncTask 来完成数据工作,您可以在其中更新列表。当然,适配器会执行此操作,您必须通知它有关数据更改的信息。

这对你有帮助How to update listview after calling Asynctask to call webservice ,我认为,

关于Android - 使用按钮控制 fragment 内的 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9197793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com