
search = (button)findVIEwByID(R.ID.search); search.setonClickListener( new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { String productname = prodname.getText().toString().trim(); if (NetworkManager.isOnline(getApplicationContext())){ // Go to Other screen AsyncFetcher results = new AsyncFetcher(currActivity); String _url = "http://192.168.1.3:3000/search.Json? utf8=%E2%9C%93&q="+productname; // progressDialog = ProgressDialog.show( // ClassifIEdsActivity.this,"","Loading..."); results.execute(_url); } else { // Throw some warning saying no internet // connection was found } } }); 一旦我的执行完成,我就会在我的活动中实例化片段:
ResultFragment resultfrag = new ResultFragment();getSupportFragmentManager().beginTransaction() .replace(R.ID.content_frame,resultfrag).commit();
但是它似乎没有用列表片段替换我的内容.
这是我的布局文件:
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <FrameLayout androID:ID="@+ID/content_frame" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /></linearLayout>解决方法 首先替换片段就像刷新一样.是的,它会重新加载其中的每个视图和数据.但是你必须将它与你的新数据联系起来.因此,我建议您在片段中创建一个刷新方法,并将此方法发送给刷新的数据,然后将您的适配器作为dataSetChanged通知.
要实现这一点,您需要访问当前附加的片段并调用其刷新方法.您可以使用findFragmentByTag来实现它.
编辑:澄清一点点
完成AsyncTask之后,你应该在onPostExecute方法上做这样的事情:
ResultFragment resultFrag = (ResultFragment) getSupportFragmentManager() .findFragmentByTag("FragToRefresh");if (resultFrag != null) { resultFrag.refreshData(refreshedArray);} 在ResultFragment中你需要有refreshData方法,如下所示:
public voID refreshData(ArrayList<YourObject> data) { yourArray = new ArrayList<YourObject>(data); yourAdapter.notifyDataSetChanged();} 并且只要您的任务完成,您的列表就会刷新.
总结以上是内存溢出为你收集整理的AsyncTask之后的Android刷新片段视图全部内容,希望文章能够帮你解决AsyncTask之后的Android刷新片段视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)