有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java滑动列表项+PullToRefresh效果+单击事件+垂直滚动

我需要一个垂直滚动的列表视图,允许拉刷新效果,每个单元格必须允许滑动(显示下面的按钮)。此外,整个ListView包含在一个三个选项卡的活动中。它与Android版的Gmail应用非常相似,它在收件箱中允许垂直滚动、滑动以存档对话,以及点击阅读电子邮件

  • “常规”活动包含从developer中提取的选项卡(使用水平滚动视图、SlidingTabStrip和ViewPager构建的SlidingTabLayout)。安卓com
  • 每个选项卡都包含一个带有框架布局和47度SwipeListView的片段。它们附在这里
  • 我们已经禁用了选项卡的水平移动(它们只需单击标题即可工作)
  • 我附加了单元格的布局和处理所有事情的java类
  • 我实现了47度SwipeList库(https://github.com/47deg/安卓-swipelistview

我面临的错误是:一方面,刷卡的单元格没有收到主单击,当我刷卡时,会显示下面的按钮,但没有正确收到单击。如果我们启用pull刷新,则刷卡将停止正常工作

布局\u列表\u项目\u联系人。xml:

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:orientation="horizontal"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent">

    <RelativeLayout
        安卓:orientation="vertical"
        安卓:id="@+id/back"
        安卓:tag="back"
        安卓:layout_width="match_parent"
        安卓:layout_height="70dp"
        安卓:background="@color/gold">

        <ImageView
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:id="@+id/btFavorite"
            安卓:background="@drawable/abc_btn_rating_star_off_mtrl_alpha"
            安卓:layout_alignParentLeft="false"
            安卓:adjustViewBounds="true"
            安卓:contentDescription="Favorite"
            安卓:layout_centerVertical="true"
            安卓:layout_marginLeft="15dp" />
    </RelativeLayout>

    <LinearLayout
        安卓:id="@+id/front"
        安卓:tag="front"
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        安卓:background="#ffffffff"
        安卓:layout_marginLeft="5dp">
    <include 安卓:id="@+id/layout_list_item_image" layout="@layout/layout_list_item_image"
        安卓:layout_width="70dp"
        安卓:layout_height = "70dp"
        安卓:layout_alignParentLeft="true"
        安卓:layout_alignParentTop="true" />
    <include 安卓:id="@+id/layout_list_item_content" layout="@layout/layout_list_item_content"
        安卓:layout_width="184dp"
        安卓:layout_toRightOf="@id/layout_list_item_image"
        安卓:layout_height="70dp"
        安卓:layout_centerHorizontal="true"
        />
    <include 安卓:id="@+id/layout_list_item_status"
        layout="@layout/layout_list_item_status"
        安卓:layout_width="match_parent"
        安卓:layout_height = "wrap_content"
        安卓:layout_alignParentRight="true"
        安卓:layout_alignParentTop="true"/>
    </LinearLayout>
</FrameLayout >

布局\u片段\u寻呼机\u联系人\u列表。xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:orientation="vertical"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:clickable="false"
    >
    <FrameLayout
        安卓:layout_width="match_parent"
        安卓:layout_height="0dip"
        安卓:layout_weight="1"
        安卓:clickable="false">

        <com.fortysevendeg.swipelistview.SwipeListView
            xmlns:swipe="http://schemas.安卓.com/apk/res-auto"
            安卓:id="@安卓:id/list"
            安卓:listSelector="#00000000"
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            swipe:swipeFrontView="@+id/front"
            swipe:swipeBackView="@+id/back"
            swipe:swipeActionRight="reveal"
            swipe:swipeMode="right"
            swipe:swipeCloseAllItemsWhenMoveList="true"
            swipe:swipeOpenOnLongPress="false"
            swipe:swipeAnimationTime="350"
            swipe:swipeOffsetLeft="280dp"
            swipe:swipeOffsetRight="280dp"
            />

        <!-- View to show if the list is emtpy -->
        <TextView 安卓:id="@安卓:id/empty"
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            安卓:textAppearance="?安卓:attr/textAppearanceMedium"
            安卓:text="No items."
            安卓:clickable="false"/>

    </FrameLayout>

</LinearLayout>

ContactListFragment。java

package com.davduran.myapp.contacts.view;

import 安卓.app.Activity;
import 安卓.content.Intent;
import 安卓.os.Bundle;
import 安卓.os.Handler;
import 安卓.os.Parcelable;
import 安卓.support.v4.app.ListFragment;
import 安卓.support.v4.view.ViewPager;
import 安卓.util.Log;
import 安卓.view.LayoutInflater;
import 安卓.view.View;
import 安卓.view.ViewGroup;
import 安卓.widget.ListView;
import 安卓.widget.TextView;

import com.fortysevendeg.swipelistview.SwipeListView;
import com.davduran.myapp.R;
import com.davduran.myapp.contacts.connection.ContactController;
import com.davduran.myapp.contacts.detail.ContactDetailMainActivity;
import com.davduran.myapp.util.Constants;
import com.davduran.myapp.util.Utils;
import com.davduran.myapp.view.tab.SlidingTabLayout;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

import io.realm.Realm;
import model.Contact;
import model.FavouriteContact;
import model.RecentContact;

/**
 * A fragment representing a list of Items.
 * <p/>
 * <p/>
 * Activities containing this fragment MUST implement the {@link OnFragmentInteractionListener}
 * interface.
 */
public class ContactListFragment extends ListFragment {

    private SlidingTabLayout mSlidingTabLayout;
    private ViewPager mViewPager;
    private Realm realm;
    private ContactController mContactController;
    private ArrayList<Contact> contactList;
    private ArrayList<FavouriteContact> favouriteContactList;
    private ArrayList<RecentContact> recentContactList;
    protected Handler handler = new Handler();

    private ContactListViewArrayAdapter adapter;
    private SwipeListView swipeListView;
    private ListView listView;
    private Parcelable state;
    private TextView emptyText;

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private int mIndex;
    private String mParam2;

    private OnFragmentInteractionListener mListener;

    // TODO: Rename and change types of parameters
    public static ContactListFragment newInstance(int index, String param2) {
        ContactListFragment fragment = new ContactListFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, index);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
       View v = inflater.inflate(R.layout.layout_fragment_pager_contact_list, container, false);
       listView = (ListView) v.findViewById(安卓.R.id.list);
       emptyText = (TextView) v.findViewById(安卓.R.id.empty);

       return v;
    }

    /**
     * Mandatory empty constructor for the fragment manager to instantiate the
     * fragment (e.g. upon screen orientation changes).
     */
    public ContactListFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        realm = Realm.getInstance(getActivity());
        mContactController = new ContactController(getActivity(),realm);
        if (getArguments() != null) {
            mIndex = getArguments().getInt(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

        setListAdapterTabs();

    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Log.i(Constants.TAG, "ContactListFragment.onListItemClick: Listclicking");
        if (mListener != null) {
            // Notify the active callbacks interface (the activity, if the
            // fragment is attached to one) that an item has been selected.
            //mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).getId());
            Intent in = new Intent(getActivity(), ContactDetailMainActivity.class);
            if(mIndex == Constants.CONTACTS_ALL) {
                in.putExtra(Constants.CONTACT_ID,contactList.get(position).getId() );
                startActivity(in);
            } else if (mIndex == Constants.CONTACTS_RECENT) {
                try {
                    String action = recentContactList.get(position).getAction();
                    if (action.compareTo("call") == 0) {
                        String strPhones = recentContactList.get(position).getPhones();
                        if (strPhones != null) {
                            JSONArray jPhones = new JSONArray(strPhones);
                            String phone = (String)((JSONObject) jPhones.get(0)).get("phone");
                            Utils.launchCall(phone, getActivity());
                        }
                    }
                    else if (action.compareTo("sms") == 0) {
                        String strPhones = recentContactList.get(position).getPhones();
                        if (strPhones != null) {
                            JSONArray jPhones = new JSONArray(strPhones);
                            String phone = (String)((JSONObject) jPhones.get(0)).get("phone");
                            Utils.launchSms(phone, getActivity());
                        }
                    }
                    else if (action.compareTo("email") == 0) {
                        String strEmails = recentContactList.get(position).getEmails();
                        if (strEmails != null) {
                            JSONArray jPhones = new JSONArray(strEmails);
                            String email = (String)((JSONObject) jPhones.get(0)).get("email");
                            Utils.launchEmail(email, getActivity());
                        }
                    }
                } catch (Exception ex) {
                    Log.e(Constants.TAG, "ContactListFragment.onListItemClick: ", ex);
                }
            } else if (mIndex == Constants.CONTACTS_FAVOURITE) { {
                in.putExtra(Constants.CONTACT_ID,favouriteContactList.get(position).getId() );
                startActivity(in);
            }}

        }
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.安卓.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        public void onFragmentInteraction(String id);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        realm.close();
    }

    public void setListAdapterTabs(){
        Log.i(Constants.TAG, "ContactListFragment.setListAdapterTabs: index " + mIndex);
        if(mIndex == Constants.CONTACTS_FAVOURITE) {
            favouriteContactList = mContactController.getAllFavouriteContacts();
            if (favouriteContactList!=null) {
                setListAdapter(new ContactFavouriteListViewArrayAdapter(getActivity().getApplicationContext(),
                        favouriteContactList));
            }
        }else if(mIndex == Constants.CONTACTS_RECENT){
            if (emptyText!=null)
                emptyText.setText("");
            recentContactList = mContactController.getAllRecentContacts();
            if (recentContactList!=null) {
               setListAdapter(new RecentListViewArrayAdapter(getActivity().getApplicationContext(), recentContactList));
            }
        }else if(mIndex == Constants.CONTACTS_ALL){
            if (emptyText!=null)
                emptyText.setText("");
            contactList = mContactController.getAllContacts();
            adapter = new ContactListViewArrayAdapter(getActivity().getApplicationContext(), contactList);
            if (contactList!=null) {
                if (listView!=null)
                    state = listView.onSaveInstanceState();
                if (adapter != null){
                    setListAdapter(adapter);
                    if (state!=null)
                        listView.onRestoreInstanceState(state);
                } else {
                    adapter = new ContactListViewArrayAdapter(getActivity().getApplicationContext(), contactList);
                    setListAdapter(adapter);
                    if (state!=null)
                        listView.onRestoreInstanceState(state);
                }
            }
        }
    }
}

共 (0) 个答案