android 怎么刷新当前的页面。
评论完成后 怎么刷新当前的页面 ,显示出来。

解决方案 »

  1.   

    Invalidate
    不过你确定要刷新页面么?
    如果是listview之类的单单刷新他们就好了
      

  2.   

    //发送按钮
    case R.id.news_reply_post:
    //隐藏输入法
    m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    String str = mNewsReplyEditText.getText().toString();
    if(str.equals("")){
    Toast.makeText(CommentsActivity.this, "不能为空",
    Toast.LENGTH_SHORT).show();
    }
    else {
    mNewsReplyEditLayout.post(new PostCommentsThread(mNid, "广州市",
    str + "",
    new NewsDetailActivity()));
    mNewsReplyEditLayout.setVisibility(View.GONE);
    mNewsReplyImgLayout.setVisibility(View.VISIBLE);
    loader_ref();
    }
    break;
    }
    public void loader_ref()
    {
            new Thread()
    {

    public void run()
    {
    commentsAdapter.notifyDataSetChanged();  //这个刷新不起作用的
    //loaddata();
    }
    }.start();

    }
    ================================
    是listview的
    Invalidate 是怎么用的呢?
      

  3.   

    你的新评论加到commentsAdapter里面了嘛?
      

  4.   


    //获取新闻的编号
    Intent intent = getIntent();
    mNid = intent.getIntExtra("nid", 0);

    mCommentsData = new ArrayList<HashMap<String,Object>>();
    Button commentsToNewBtn = (Button) findViewById(R.id.comments_titlebar_news);
    getComments(mNid);
    commentsAdapter = new SimpleAdapter(this, mCommentsData
    , R.layout.comments_list_item_layout
    , new String[] {"commentator_from", "comment_ptime", "comment_content"}
    , new int[] { R.id.commentator_from, R.id.comment_ptime, R.id.comment_content});
    commentsList = (ListView) findViewById(R.id.comment_list);
    commentsList.setAdapter(commentsAdapter);
      

  5.   

    // 实例化一个handler    Handler handler   = new Handler()
        {
               //接收到消息后处理           public void handleMessage(Message msg)           {
                      switch (msg.what)                  {                  case 1:
                           //Log.i("--------------", "0000000000000000");             
                           Intent intent = new Intent(CommentsActivity.this,CommentsActivity.class);
           intent.putExtra("nid", mNid);
           startActivity(intent);
                           //commentsAdapter.notifyDataSetChanged();   
                        //commentsList.invalidate();        //刷新界面
                           break;                  }                  super.handleMessage(msg);           }                      };如果重新 跳转那就可以 。 不知道还有更好的方法没有呢
      

  6.   

    这个在方法说明中写了,Adapter的notifyDataSetChanged()方法的调用一般是在UI主线程才会起作用的吧,同理的invalidate()方法也是一样,需要借用Handler尚可在UI主线程起作用。为保险起见,我一般在项目的做法是组合一起用,绝对有效  :)commentsList.setAdapter(commentsAdapter);//重新为listview设置更新后的commentsAdapter
    commentsAdapter.notifyDataSetChanged(); //更新显示