private static void setListener(
      Object injectedSource, Field field, String methodName, Method method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(injectedSource);

    switch (method) {
      case Click:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new EventListener(injectedSource).click(methodName));
        }
        break;
      case ItemClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new EventListener(injectedSource).itemClick(methodName));
        }
        break;
      case LongClick:
        if (obj instanceof View) {
          ((View) obj)
              .setOnLongClickListener(new EventListener(injectedSource).longClick(methodName));
        }
        break;
      case itemLongClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(
                  new EventListener(injectedSource).itemLongClick(methodName));
        }
        break;
      default:
        break;
    }
  }
Exemple #2
0
  /**
   * 设置view的监听器.
   *
   * @param field the field
   * @param methodName the method name
   * @param method the method
   * @throws Exception the exception
   */
  private void setListener(Field field, String methodName, int method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(this);

    switch (method) {
      case AbIocEventListener.CLICK:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new AbIocEventListener(this).click(methodName));
        }
        break;
      case AbIocEventListener.ITEMCLICK:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new AbIocEventListener(this).itemClick(methodName));
        }
        break;
      case AbIocEventListener.LONGCLICK:
        if (obj instanceof View) {
          ((View) obj).setOnLongClickListener(new AbIocEventListener(this).longClick(methodName));
        }
        break;
      case AbIocEventListener.ITEMLONGCLICK:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(new AbIocEventListener(this).itemLongClick(methodName));
        }
        break;
      default:
        break;
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_debtors, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);
    mListView.setOnItemLongClickListener(this);
    mListView.setEmptyView(view.findViewById(android.R.id.empty));

    return view;
  }
  /**
   * 设置view的监听器
   *
   * @param field the field
   * @param methodName the method name
   * @param method the method
   * @throws Exception the exception
   */
  public void setListener(Field field, String methodName, EmMethod method) throws Exception {
    if (methodName == null || methodName.trim().length() == 0) return;

    Object obj = field.get(mActivity);

    switch (method) {
      case Click:
        if (obj instanceof View) {
          ((View) obj).setOnClickListener(new AbIocEventListener(mActivity).click(methodName));
        }
        break;

      case ItemClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemClickListener(new AbIocEventListener(mActivity).itemClick(methodName));
        }
        break;

      case LongClick:
        if (obj instanceof View) {
          ((View) obj)
              .setOnLongClickListener(new AbIocEventListener(mActivity).longClick(methodName));
        }
        break;

      case itemLongClick:
        if (obj instanceof AbsListView) {
          ((AbsListView) obj)
              .setOnItemLongClickListener(
                  new AbIocEventListener(mActivity).itemLongClick(methodName));
        }
        break;

      default:
        break;
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);

    View addButton = view.findViewById(R.id.add_button);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      setMaterialLayout(addButton);
    } else {
      addButton.setBackgroundResource(R.drawable.oval);
    }

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);
    mListView.setOnItemLongClickListener(this);
    mListView.setOnScrollListener(mOnScrollListener);

    return view;
  }
  @Override
  protected void onFinishInflate() {

    mFilterList = (AbsListView) findViewById(R.id.filteredList);
    mFilterList.setTextFilterEnabled(true);

    mEmptyView = (TextView) findViewById(R.id.empty);

    mFilterList.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor c = (Cursor) mFilterList.getItemAtPosition(position);

            if (mListener != null) mListener.openChat(c);
          }
        });

    mFilterList.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(
              AdapterView<?> arg0, View arg1, final int position, long arg3) {

            String[] contactOptions = {
              //        mContext.getString(R.string.menu_verify),
              mContext.getString(R.string.menu_contact_nickname),
              mContext.getString(R.string.menu_remove_contact)
            };
            //      mContext.getString(R.string.menu_block_contact)};

            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setItems(
                contactOptions,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // The 'which' argument contains the index position
                    // of the selected item

                    if (which == 0) setContactNickname(position);
                    else if (which == 1) removeContactAtPosition(position);
                    else if (which == 2) blockContactAtPosition(position);
                  }
                });

            builder.create().show();

            return true;
          }
        });

    /**
     * mEtSearch = (EditText)findViewById(R.id.contactSearch);
     *
     * <p>mEtSearch.addTextChangedListener(new TextWatcher() { @Override public void
     * afterTextChanged(Editable s) {
     *
     * <p>} @Override public void beforeTextChanged(CharSequence s, int start, int count, int after)
     * {
     *
     * <p>} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {
     *
     * <p>ContactListFilterView.this.doFilter(mEtSearch.getText().toString());
     *
     * <p>}
     *
     * <p>});
     *
     * <p>mEtSearch.setOnKeyListener(new OnKeyListener () { @Override public boolean onKey(View v,
     * int keyCode, KeyEvent event) {
     *
     * <p>ContactListFilterView.this.doFilter(mEtSearch.getText().toString()); return false; }
     *
     * <p>});
     */

    /*
        mFilterList.setItemActionListener(new ListView.OnActionClickListener() {

            @Override
            public void onClick(View listView, View buttonview, int position) {

                Cursor c = (Cursor) mFilterList.getItemAtPosition(position);
                if (mListener != null)
                    if (buttonview.getId() == R.id.btnExListChat)
                        mListener.startChat(c);
                    else if (buttonview.getId() == R.id.btnExListProfile)
                        mListener.showProfile(c);

            }
    }, R.id.btnExListChat, R.id.btnExListProfile);
    */

    //

    // if (!isInEditMode())
    //  mPresenceView = (UserPresenceView) findViewById(R.id.userPresence);

  }