2016-01-20 73 views
-4

公共類MyActivity擴展ActionBarActivity實現OnTouchListener {ontouch listner在一個圖像上正常工作,但不能在同一活動中的secpnd圖像上工作?

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

}

圖像的觸摸聽者leftslidee工作正常但不沃金圖像leftslide?這個問題的任何解決方案...

回答

2

他們都在左側,一個覆蓋另一個。這兩種情況都與R.id.leftslide有關。

編輯: 哦,對於上帝的愛,這些變量的名稱。不介意第一部分,只是關於案件的一部分。

+0

我明白了,謝謝... –

+0

@GouravSharma請閱讀這篇文章http://codebuild.blogspot.com/2012/02/15-best-practices-of-variable-method.html尤其是nr.6,它將在未來幫助你解決很多錯誤。 – somerandomusername

+0

好的,謝謝你的... –

相關問題