fragment:

/**
* author: Created by zzl on 15/11/19.
*/
@SuppressLint("validFragment")
public class pushMealHistoryFragment extends Fragment { Context ctxt;
View gridALl;
public pushMealHistoryFragment(Context ctxt)
{
this.ctxt = ctxt;
} @Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { gridALl = inflater.inflate(R.layout.fragment_push_meal_history, null); return gridALl;
} public void updateGridview()
{
final GridView gridviewHistory = (GridView)gridALl.findViewById(R.id.gridview_pushing_history);
final Button btnBackground = (Button)gridALl.findViewById(R.id.empty_meal_done_history_gridview); ApisManager.getMealPushedHistory(CommonUtils.getFormatDate(0), new ApiCallback() {
@Override
public void success(final Object object) { getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
HandlerUtils.showToast(ctxt, "hello,i'm refreshing...");
List<PushHistoryFood> list = (List<PushHistoryFood>) object;
PushHistoryAdapterr adapter = new PushHistoryAdapterr(ctxt, list);
gridviewHistory.setAdapter(adapter);
if (list.size() == 0) {
btnBackground.setVisibility(View.VISIBLE);
} else {
btnBackground.setVisibility(View.INVISIBLE);
}
}
}); } @Override
public void error(BaseApi.ApiResponse response) { }
});
} }

如果要在activity中调用上面的fragment的updateGridview方法,demo:

/**
* author: Created by zzl on 15/11/19.
*/
public class PushMealActivity extends BaseActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mealdone);
init();
} public void init()
{ Fragment fragmentPushMealHistory = new pushMealHistoryFragment(ctxt);
//在这里调用fragmentPushMealHistory的updateGridview方法
((pushMealHistoryFragment)fragmentPushMealHistory).updateGridview(); } }

2015.11.27更新:

根本原因是fragmentPushMealHistory定义的类型为Fragment,如果为pushMealHistoryFragment,则不需要做强制转换了

最新文章

  1. 7.7 使用rollup子句
  2. asp.net模态窗口返回值
  3. 读取pdf文件 .选择了itextsharp 库
  4. css:hover选择器
  5. Z-Stack协议中几个重要概念的理解
  6. zoj 3706 Break Standard Weight
  7. SQL SERVER IN参数化处理
  8. keepalived+nginx负载均衡+ApacheWeb实现高可用
  9. Eclipse快捷键 10个最有用的快捷键(转载收藏)
  10. 《算法》第四章部分程序 part 4
  11. mysql 存储过程中结尾分割符修改
  12. 使用MAVEN打JAR,直接使用
  13. REST接口调用经验
  14. private、protected、public
  15. java压缩多个文件
  16. table实现 js数据访问 传递json数据用render_to_response
  17. windows8安装docker(tool box)
  18. devexpress 经验笔记
  19. numpy array转置与两个array合并
  20. [Algorithm] JavaScript Graph Data Structure

热门文章

  1. 碎碎念css
  2. 零基础逆向工程28_Win32_02_事件_消息_消息处理函数
  3. xaml实现无边框窗口
  4. Compaq Visual Fortran生成静态库的方法及使用
  5. Android 关于Acitivity 的setFlag以及launchmode的总结
  6. 【C++函数重载】求3个数中最大的数(分别考虑整数、双精度数、长整数的情况)。
  7. python使用浮点类型float计算后,数值不对_20180827
  8. 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms 这个实现是不是Windows平台FIPS验证的加密算法。解决方法
  9. 5分钟了解Java 12 八大新特性
  10. Dropout &amp; Maxout