Android-将SwipeView用于整个ListView [英] Android - Using SwipeView for an entire ListView

查看:292
本文介绍了Android-将SwipeView用于整个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了在以下位置实现的SwipeViews的几个示例(此处) ListView,但这些仅用于列表中的单个项目,而不适用于ListView本身.

I've seen several examples (here) of SwipeViews that are implemented on a ListView, but these are for individual items on the list and not for the ListView itself.

在我的应用中,意图是从一个Listview项开始的,并将您发送到相关的Listview.从那里,我想实现某种功能,允许我从一个ListView滑动到另一个ListView.在这种情况下,始终不停地深入研究意图并不会像SwipeView那样提供用户友好的体验.

In my app, an intent is started from one Listview item and that sends you to the Listview in question. From there, I would like to implement some kind of function that allows me to swipe from one ListView to another. Drilling down with intents all the time would not provide as user-friendly an experience as SwipeView would, in this instance.

如果我没有清楚地说明这一点,请告诉我.如果我必须创建额外的类和XML布局文件来执行此操作,就可以了.

If I haven't explained this clearly, please let me know. If I have to create extra classes and XML layout files to do this, then so be it.

CustomListAdapter.java(保存ListView代码的类)

CustomListAdapter.java (The class which holds the ListView code)

public class CustomListAdapter extends ArrayAdapter<String> {
    private Context mContext;
    private int id;
    private ArrayList<String> callData;
    private String[] headers = {"Number", "Customer Number", "Name", "Bill to Customer Number", "Bill to Name",
            "Order Date", "Order Time", "Response Date", "Response Time", "Fix by Date", "Fix by Time",
            "Responded Date", "Responded Time", "Fixed Date", "Fixed Time", "Your Reference",
            "Description", "Transaction Status", "Ship to Code", "Ship to Name", "Ship to Address",
            "Ship to Address 2", "Ship to City", "Ship to County", "Ship to Postcode", "Contact Name",
            "Phone Number", "Note", "Sources"};

    public CustomListAdapter(Context context, int textViewResourceId, ArrayList<String> callData) {
        super(context, textViewResourceId, callData);
        this.callData = callData;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.list_service_order, null);
        }

        String test = callData.get(position);

        if (test != null) {
            TextView customerNoLabel = (TextView) view.findViewById(R.id.name_label);
            TextView customerNoData = (TextView) view.findViewById(R.id.listed_data);

            if (customerNoLabel != null) {
                customerNoLabel.setText(headers[position]);
                customerNoData.setText(callData.get(position));
            }
        }
        return view;
    }
}

CallActivity2.java(该类实现了CustomListAdapter的代码,并且我想用来滑动到具有不同标题和值的两个不同列表视图)

CallActivity2.java (The class that implements the code for the CustomListAdapter and which I want to use to swipe to two different listview with different headings and values)

    public class CallActivity2 extends ListActivity {
    private ArrayList<String> individualCallData;
   // private ArrayAdapter<String> callDataAdapter;
    private CustomListAdapter callDataAdapter;
    private ListView callDataView;
    private Runnable viewParts;
    private TextView serviceOrderNo;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.call_display);

        Intent intent = getIntent();
        individualCallData = intent.getStringArrayListExtra("Call");

        // Instantiate CustomListAdapter class
        callDataView = (ListView) findViewById(android.R.id.list);
        callDataAdapter = new CustomListAdapter(this, R.layout.list_service_order, individualCallData);
        setListAdapter(callDataAdapter);



        viewParts = new Runnable(){
            public void run(){
                handler.sendEmptyMessage(0);
            }
        };

        // here we call the thread we just defined - it is sent to the handler below.
        Thread thread =  new Thread(null, viewParts, "MagentoBackground");
        thread.start();


    }

    private Handler handler = new Handler() {
        public void handleMessage(Message msg)
        {
            // create some objects
            // here is where you could also request data from a server
            // and then create objects from that data.
            //individualCallData.add("Test");

            callDataAdapter = new CustomListAdapter(CallActivity2.this, R.layout.list_service_order, individualCallData);

            // display the list.
            setListAdapter(callDataAdapter);

        }
    };
}

推荐答案

相反,我决定摆脱ListView并改用ScrollView.我可以做的事情有更多的灵活性.此外,我也可以滚动和滑动. Listview不会这样做,并且它不是项目单击.谢谢两个人的贡献.

Instead, I decided to get rid of the ListView and use ScrollView instead. There is more flexibility in what I can do. Furthermore, I can scroll and swipe, too. Listview doesn't do that and it is not an item click. Thank you for the two guys that contributed though.

这篇关于Android-将SwipeView用于整个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆