// 点击事件 @SuppressLint("NewApi") @Override public void onClick(View v) { switch (v.getId()) { case R.id.common_back: finish(); break; case R.id.rb_notification: isFalg = 0; page = 1; if (adapter_m.getmMessage_list() != null) adapter_m.getmMessage_list().clear(); adapter_m.notifyDataSetChanged(); mPullList.getRefreshableView().setAdapter(adapter_n); setRadioButton(); mNotification.setBackground(getResources().getDrawable(R.drawable.rd_message_l)); mNotification.setTextColor(getResources().getColor(R.color.white)); getData(); break; case R.id.rb_message: isFalg = 1; page = 1; if (adapter_n.getmMessage_list() != null) adapter_n.getmMessage_list().clear(); adapter_n.notifyDataSetChanged(); mPullList.getRefreshableView().setAdapter(adapter_m); setRadioButton(); mMessage.setBackground(getResources().getDrawable(R.drawable.rd_message_r)); mMessage.setTextColor(getResources().getColor(R.color.white)); getData(); break; default: break; } }
// 设置下拉刷新========== public void setPullRefresh() { mPullList.setPullLoadEnabled(false); // 滚动到底自动加载可用 mPullList.setScrollLoadEnabled(true); // 得到实际的ListView 设置点击 mPullList .getRefreshableView() .setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (isFalg == 1) { Intent detail = new Intent(UserNotificationMessageActivity.this, UserMessageDetail.class); UserMessageListEntity bean = (UserMessageListEntity) adapter_m.getItem(position); int friend_id = bean.getFriend_id(); detail.putExtra("friend_id", friend_id + ""); detail.putExtra("friend_name", bean.getName()); startActivity(detail); } } }); // 设置下拉刷新的listener mPullList.setOnRefreshListener( new OnRefreshListener<ListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { isRefresh = true; page = 1; getData(); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { page++; getData(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac_user_message); ViewUtils.inject(this); if (adapter_m == null) { adapter_m = new UserMessageAdapter(this); adapter_n = new UserNotificationAdapter(this); mPullList.getRefreshableView().setAdapter(adapter_n); } else { adapter_m.notifyDataSetChanged(); adapter_n.notifyDataSetChanged(); } setPullRefresh(); // 初始化下拉刷新 initData(); // 初始化数据 }
// 关闭刷新 private void onLoaded() { mPullList.onPullDownRefreshComplete(); mPullList.onPullUpRefreshComplete(); }