OnTouch Listner在一个图像上工作正常,但在同一活动中无法处理SECPND图像



public class MyActivity extensions ActionBarActivity 实现 OnTouchListener {

SimpleSideDrawer mSlidingMenu;
LinearLayout Commercial, residencial, loyalityinfo, postproperty,
        setpropertyalrt, setting, myactivity, postrequirement;
ImageView menu, login, signup;
LinearLayout menulayout;
ImageView logout, leftslide, leftslidee, logo;
TextView my;
String uid, username;
ImageView myreq, rentsale;
TransparentProgressDialog pdialog;
Toolbar toolbar;
ViewPager pager;
ViewPagerAdptr adapter;
SlidingTabLayut tabs;
CharSequence Titles[] = { "My Properties", "My Requirements", "My Favorite" };
int Numboftabs = 3;
LinearLayout tablayout, simplelayout;
String sucess;
ConnectionStatus status;
boolean isConnected;
AlertDialog alertDialog;
double latitude, longitude;
String regId;
@SuppressWarnings("deprecation")
@Override
protected void onStart() {
    super.onStart();
    isConnected = status.isConnected();
    if (isConnected) {
    } else {
        if (pdialog.isShowing())
            pdialog.dismiss();
        alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("ChdProperty");
        alertDialog.setMessage("No Internet Connection Available");
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent dialogIntent = new Intent(
                        android.provider.Settings.ACTION_SETTINGS);
                dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(dialogIntent);
            }
        });
        alertDialog.show();
    }
}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_my);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.hide();
    status = new ConnectionStatus(this);
    SharedPreferences acc = getSharedPreferences("account", 1);
    uid = acc.getString("uid", "");
    username = acc.getString("username", "");
    pdialog = new TransparentProgressDialog(this, R.drawable.loader);
    tablayout = (LinearLayout) findViewById(R.id.tablayout);
    simplelayout = (LinearLayout) findViewById(R.id.simplelayout);
    myactivity();
    Log.d("SESSIONACCOUNT", "Username >> " + username);
    Log.d("SESSIONACCOUNT", "Username >> " + username);
    Log.d("SESSIONACCOUNT", "Username >> " + username);
    mSlidingMenu = new SimpleSideDrawer(this);
    mSlidingMenu.setLeftBehindContentView(R.layout.behind_menu_left);
    residencial = (LinearLayout) findViewById(R.id.residencialmenulayout);
    Commercial = (LinearLayout) findViewById(R.id.commercialmenulayout);
    loyalityinfo = (LinearLayout) findViewById(R.id.loyalityinfomenulayout);
    postproperty = (LinearLayout) findViewById(R.id.postpropertymenulayout);
    setpropertyalrt = (LinearLayout) findViewById(R.id.propertyalertmenulayout);
    postrequirement = (LinearLayout) findViewById(R.id.postrequirementmenulasgfyout);
    myactivity = (LinearLayout) findViewById(R.id.myactivitymenulayout);
    setting = (LinearLayout) findViewById(R.id.settingmenulayout);
    logo = (ImageView) findViewById(R.id.logo);
    login = (ImageView) findViewById(R.id.buttonhomelogin);
    signup = (ImageView) findViewById(R.id.buttonhomeregister);
    menulayout = (LinearLayout) findViewById(R.id.menulayout);
    menu = (ImageView) findViewById(R.id.homemenuimgcom);
    leftslide = (ImageView) findViewById(R.id.leftslidee);
    leftslidee = (ImageView) findViewById(R.id.leftslide);
    logout = (ImageView) findViewById(R.id.buttonlogout);
    my = (TextView) findViewById(R.id.textViewmyname);
    myreq = (ImageView) findViewById(R.id.imageViewreq);
    rentsale = (ImageView) findViewById(R.id.imageViewrent);
    if (username.equalsIgnoreCase("")) {
        Log.d("Sesionif", "equal2null");
        Log.d("Sesionif", "equal2null");
        Log.d("Sesionif", "equal2null");
        my.setVisibility(View.INVISIBLE);
        logout.setVisibility(View.INVISIBLE);
        login.setVisibility(View.VISIBLE);
        signup.setVisibility(View.VISIBLE);
        Log.d("Sesionif", "equal2null");
        Log.d("Sesionif", "equal2null");
        Log.d("Sesionif", "equal2null");
    } else {
        Log.d("Sesionif", "equal2value");
        Log.d("Sesionif", "equal2value");
        Log.d("Sesionif", "equal2value");
        my.setVisibility(View.VISIBLE);
        logout.setVisibility(View.VISIBLE);
        my.setText(username);
        login.setVisibility(View.INVISIBLE);
        signup.setVisibility(View.INVISIBLE);
        Log.d("Sesionif", "equal2value");
        Log.d("Sesionif", "equal2value");
        Log.d("Sesionif", "equal2value");
    }
    OnTouchListener touchListener = new OnTouchListener() {
        float previouspoint = 0;
        float startPoint = 0;
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (v.getId()) {
            case R.id.leftslide: // Give your R.id.sample ...
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // startPoint = event.getX();
                    // System.out.println("Action down,..." + event.getX());
                    mSlidingMenu.toggleDrawer();
                    break;
                case MotionEvent.ACTION_MOVE:
                    // mSlidingMenu.toggleDrawer();
                    break;
                case MotionEvent.ACTION_CANCEL:
                    previouspoint = event.getX();
                    if (previouspoint > startPoint) {
                        mSlidingMenu.toggleDrawer();
                    } else {
                        mSlidingMenu.toggleDrawer();
                    }
                    break;
                }
                break;
            }
            return true;
        }
    };
    leftslide.setOnTouchListener(touchListener);
    OnTouchListener ThumbTouch = new OnTouchListener() {
        float previouspoint = 0;
        float startPoint = 0;
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (v.getId()) {
            case R.id.leftslide: // Give your R.id.sample ...
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // startPoint = event.getX();
                    // System.out.println("Action down,..." + event.getX());
                    mSlidingMenu.toggleDrawer();
                    break;
                case MotionEvent.ACTION_MOVE:
                    // mSlidingMenu.toggleDrawer();
                    break;
                case MotionEvent.ACTION_CANCEL:
                    previouspoint = event.getX();
                    if (previouspoint > startPoint) {
                        mSlidingMenu.toggleDrawer();
                    } else {
                        mSlidingMenu.toggleDrawer();
                    }
                    break;
                }
                break;
            }
            return true;
        }
    };
    leftslidee.setOnTouchListener(ThumbTouch);

    menulayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mSlidingMenu.toggleDrawer();
        }
    });
}

@Override
public void onBackPressed() {
    if (username.equalsIgnoreCase("")) {
        Log.d("Sesionif", "equal2null");
        Log.d("Sesionif", "equal2null");
        Log.d("Sesionif", "equal2null");
        Intent i = new Intent(MyActivity.this, ResidencialActivity.class);
        // i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(i);
    } else {
        Log.d("Sesionif", "equal2value");
        Log.d("Sesionif", "equal2value");
        Log.d("Sesionif", "equal2value");
        finish();
    }
    super.onBackPressed();
}
public void myactivity() {
    pdialog.show();
    String logou = "http://www.chandigarhpropertyonline.com/api/MyActivityAPI.php?uid=";
    String url = logou + uid;
    Log.d("GetLogouturllll", url);
    Log.d("GetLogouturllll", url);
    Log.d("GetLogouturllll", url);
    Request hh = (Request) new Request(url) {
        @Override
        protected void onComplete(Transport transport) {
            super.onComplete(transport);
            JSONObject jsonobj = transport.getResponseJson();
            Log.d("getprofileresponse", "" + jsonobj);
            try {
                sucess = jsonobj.getString("success");
                // JSONObject use = jsonobj.getJSONObject("user");
                if (pdialog.isShowing()) {
                    pdialog.dismiss();
                }
                if (sucess.equals("1")) {
                    // if (sucess.equals("1")) {
                    tablayout.setVisibility(View.VISIBLE);
                    simplelayout.setVisibility(View.GONE);
                    adapter = new ViewPagerAdptr(
                            getSupportFragmentManager(), Titles, Numboftabs);
                    pager = (ViewPager) findViewById(R.id.pager);
                    pager.setAdapter(adapter);
                    tabs = (SlidingTabLayut) findViewById(R.id.tabs);
                    tabs.setDistributeEvenly(true);
                    tabs.setCustomTabColorizer(new SlidingTabLayut.TabColorizer() {
                        @Override
                        public int getIndicatorColor(int position) {
                            return getResources().getColor(
                                    R.color.tabsScrollColor);
                        }
                    });
                    tabs.setViewPager(pager);
                } else {
                    tablayout.setVisibility(View.GONE);
                    simplelayout.setVisibility(View.VISIBLE);
                }
            } catch (JSONException e) {
                if (pdialog.isShowing()) {
                    pdialog.dismiss();`
                }
                e.printStackTrace();
            }
        }
    }.execute("GET");
}
@Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    return false;
}

}

图像左

滑块上的触摸列表器工作正常,但在图像左幻灯片上没有醒来? 这个问题的任何解决方案...

它们都在左侧滑动,一个覆盖另一个。这两种情况都与R.id.leftslide有关。

编辑:哦,为了爱上帝,这些变量名称。不介意第一部分,只介意关于案例的部分。

最新更新