1

I need to implement slide action event in my listview.

Call event should happen if i slide from left to right in every component of the lsitview. Below is my link for my code. kindly provide some suggestions.

@SuppressWarnings("unused")
public class CityList extends Activity{
    private static final String SOAP_ACTION = "http://com.kumaran/TestSericve";      
    private static final String METHOD_NAME = "getCityName";      
    private static final String NAMESPACE = "http://kumaran.com";      
    private static final String URL = "http://xxxxxxxxx.com?wsdl";
    ListView lv;
    ArrayList<String> cityName=new ArrayList<String>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.citylist);
        lv=(ListView)findViewById(R.id.listView1);
        SoapObject soapReq=new SoapObject(NAMESPACE, METHOD_NAME);  
        SoapSerializationEnvelope soapenv= new SoapSerializationEnvelope(SoapEnvelope.VER11);           
        soapenv.setOutputSoapObject(soapReq);           
        HttpTransportSE ht=new HttpTransportSE(URL);
        try
        {
            ht.call(SOAP_ACTION, soapenv);        
            SoapObject result=(SoapObject)soapenv.bodyIn;           
            for(int i=0; i<result.getPropertyCount();i++){
                cityName.add(result.getProperty(i).toString()); 
            }
            lv.setAdapter(new ArrayAdapter<String>(CityList.this,android.R.layout.simple_list_item_1,cityName));
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> arg0, View view,
                        int i, long l) {
                    String cityName=lv.getItemAtPosition(i).toString();
                    Pojo.setCityName(cityName);
                    Intent int1=new Intent(CityList.this,CustomerList.class);
                    startActivity(int1);
                }
            });
        }
        catch(Exception e)
        {
            Log.e("Exception ", e.getMessage());
        }           
    }
}
Satheesh
  • 646
  • 1
  • 10
  • 33
  • 1
    what have you tried? Please avoid posting links to code, prefer posting the actual code. If its too big to fit nicely - It's probably too big period. Then try to narrow down the problem into a shorter example. – vidstige May 14 '12 at 11:09
  • I tried an onItemClick already. I need to implement a slide/swipe action from left to right which should ivnoke the call option to call that respective number where i have clicked. Post will be big i used to put more codes. I cant and hesitate to scroll down again and again if i got a new answer. I hope pasting links is not against our forum rules. Right??? – Satheesh May 14 '12 at 11:25

2 Answers2

1

here is a suggestion as far as I can understand

You want listView like above.. Simply Inflate listview by inheriting it with ArrayAdapter Class and in on draw method call inflate

Use xitij answer for horizontal scroll view, and during scroll call intent, in intent pass the inflated view by using putExtra() method, either you can call implicit intent or explicit, its upto you.

For listview inflate check these stackoverflows' questions:

Check Lars Vogella's Link:

Another link for inflating listView, close to your scenario but not exact:

Check these ones too for inflating listView:

Community
  • 1
  • 1
0

Try this code

final GestureDetector gestureDetector = new GestureDetector(
                new MyGestureDetector());
        View.OnTouchListener gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        };
        contactList.setOnTouchListener(gestureListener);

And make a inner class in your activity

class MyGestureDetector extends SimpleOnGestureListener {

        private Button image;

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
int pos = contactList.pointToPosition((int) e1.getX(),
                    (int) e1.getY());

            if (Math.abs(e1.getY() - e2.getY()) > REL_SWIPE_MAX_OFF_PATH) {
                return false;
            }
            if (e1.getX() - e2.getX() > REL_SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) {

                int firstPosition = contactList.getFirstVisiblePosition()
                        - contactList.getHeaderViewsCount(); // This is the same
                                                                // as child #0
                int wantedChild = pos - firstPosition;

//Get the phone no from this position in your contact list and try this
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phone));
context.startActivity(intent);

}
Stack Overflow User
  • 4,052
  • 6
  • 29
  • 47
Jitendra
  • 1,015
  • 9
  • 24