从左向右滑动拨打电话(如三星联系人listview)

时间:2012-05-14 11:05:31

标签: android android-listview

我需要在listview中实现幻灯片动作事件。

如果我在lsitview的每个组件中从左向右滑动,则会发生调用事件。以下是我的代码链接。请提供一些建议。

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

2 个答案:

答案 0 :(得分:1)

据我所知,这是一个建议

你想要像上面的listView .. 简单地通过使用ArrayAdapter类继承它并使用draw方法调用inflate

来扩展listview

使用xitij  回答水平滚动视图,并在滚动调用意图期间,意图通过使用putExtra()方法传递膨胀的视图,您可以调用隐式意图或显式,它由您决定。

对于listview inflate,请检查这些stackoverflows的问题:

检查Lars Vogella的链接:

另一个用于充气listView的链接,靠近你的场景但不完全正确:

检查这些也是为了膨胀listView:

答案 1 :(得分:0)

试试此代码

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

在活动中制作内部课程

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

}