2012-08-04 19 views
1

根据图库的位置,一个或另一个edittext将获得焦点。虽然我可以做到这一点,但行为的图库会崩溃:当图库运行位置并将焦点放在edittext上时,图库的速度会崩溃。看起来画廊太慢,无法按时收到请求。行为图库在调用requestFocus时崩溃

我还没有找到关于它的任何重要信息。

galleryView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
    public void onItemSelected(
      @SuppressWarnings("rawtypes") AdapterView adapterView, 
      View view, int pos, long l) { 

     if (pos == 0) { 
      pie_foto_1.post(new Runnable() { 
       public void run() { 
        pie_foto_1.requestFocus(); 
       } 
      }); 
     } 

     if (pos == 1) { 
      pie_foto_2.post(new Runnable() { 
       public void run() { 
        pie_foto_2.requestFocus(); 
       } 
      }); 
     } 

     if (pos == 2) { 

      pie_foto_3.post(new Runnable() { 
       public void run() { 
        pie_foto_3.requestFocus(); 
       } 
      }); 

      pie_foto_1.setVisibility(View.INVISIBLE); 
      pie_foto_2.setVisibility(View.INVISIBLE); 
      pie_foto_3.setVisibility(View.VISIBLE); 

     } 
    } 

    public void onNothingSelected(
      @SuppressWarnings("rawtypes") AdapterView adapterView 
    ) { 
    } 
}); 

回答

0

画廊需要更多的时间来获得新的位置。所以我在画廊改变位置之前放了一段延迟,以便获得一个很好的过渡。

       else if (pos == 1) 
           { 
            Runnable mMyRunnable = new Runnable() { 
             public void run() { 
              pie_foto_1.post(new Runnable() { 
               public void run() { 
                pie_foto_2.requestFocus(); 
                // headline.clearFocus(); 

               } 
              }); 
             } 
            }; 

            Handler myHandler = new Handler(); 
            myHandler.postDelayed(mMyRunnable, 100); 
           }  
相关问题