Пример #1
0
  private void initView() {
    HashMap<Integer, String[]> fromMap = new HashMap<Integer, String[]>();
    fromMap.put(RESOUCE[0], from);
    HashMap<Integer, int[]> toMap = new HashMap<Integer, int[]>();
    toMap.put(RESOUCE[0], to);
    mAdapter =
        new SocialStreamAdapter(
            getActivity(),
            dataSource,
            RESOUCE,
            fromMap,
            toMap,
            0,
            0,
            ImageLoaderUtils.headDisplayOpts);
    dynamicLv.setAdapter(mAdapter);
    dynamicLv.setOnPullRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            curPageNo = 1;
            dynamicBeanList.clear();
            dataSource.clear();
            mAdapter.notifyDataSetChanged();
            initDataSource();
          }
        });
    mAdapter.setViewBinder(
        new SocialStreamAdapter.ViewBinder() {
          @Override
          public boolean setViewValue(View view, Object data, Object comment) {
            if (view.getId() == R.id.tv_content && data != null) {
              String str = (String) data;
              TextView tv = (TextView) view;
              tv.setText(Html.fromHtml(str));
              return true;
            }
            return false;
          }
        });
    dynamicLv.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), CollectDetailActivity.class);
            CollectDetailActivity.dynamicBeanList = dynamicBeanList;
            intent.putExtra(DynamicDetailActivity.KEY_DYNAMIC_INDEX, position);
            intent.putExtra(DynamicDetailActivity.KEY_DYNAMIC_PAGE_INDEX, curPageNo);
            startActivityForResult(intent, 0);
          }
        });
    dynamicLv.setOnLoadMoreListener(
        new FanrRefreshListView.OnLoadMoreListener() {
          @Override
          public void loadMore() {
            initDataSource();
          }
        });

    initDataSource();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_out_reservation_history);
    ButterKnife.inject(this);
    HashMap<Integer, String[]> fromMap = new HashMap<Integer, String[]>();
    fromMap.put(RESOUCE[0], from);
    HashMap<Integer, int[]> toMap = new HashMap<Integer, int[]>();
    toMap.put(RESOUCE[0], to);
    mAdapter =
        new SocialStreamAdapter(
            this, dataSource, RESOUCE, fromMap, toMap, 0, 0, ImageLoaderUtils.headDisplayOpts);
    listView.setAdapter(mAdapter);
    listView.setOnPullRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            historyBeanList.clear();
            dataSource.clear();
            mAdapter.notifyDataSetChanged();
            initDataSource();
          }
        });

    mAdapter.setViewBinder(
        new SocialStreamAdapter.ViewBinder() {
          @Override
          public boolean setViewValue(View view, Object data, Object comment) {
            if (view.getId() == R.id.tv_reservation_status
                && data != null
                && data instanceof Integer) {

              int status = (int) data;
              TextView tv = (TextView) view;
              if (status == 0) {
                tv.setTextColor(getResources().getColor(R.color.color_theme));
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.tobepaid), null, null, null);
              } else {
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.icon_finish), null, null, null);
                tv.setTextColor(getResources().getColor(R.color.text_74));
              }
              return true;
            }
            return false;
          }
        });
    listView.setCanLoadMore(false);

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent =
                new Intent(OutReservationHistoryActivity.this, OutReservationDetailActivity.class);
            OutReservationHistoryBean bean =
                (OutReservationHistoryBean) dataSource.get(position).get("data");
            intent.putExtra(OutReservationDetailActivity.KEY_OUT_RESERVATION_BEAN, bean);
            startActivity(intent);
          }
        });

    JDUtils.registerLocalReceiver(mReceiver, IntentConstants.ACTION_RESERVATION_REFRESH);
    initDataSource();
  }