javaandroidlistviewswipeview

Android - Using SwipeView for an entire 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.

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.

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 (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 (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);

        }
    };
}

Solution

  • 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.