2010-11-17 36 views
9

मेरे एंड्रॉइड एप्लिकेशन में, खींचने योग्य फ़ोल्डर में छवियों की संख्या है। मेरे लेआउट में दो बटन हैं: पीछे और अगला बटन। अगले और बैक बटन पर क्लिक करने पर 2 अलग-अलग छवियों को एक ही लेआउट (सभी छवियों के लिए आम) पर लोड किया जाता है।बटन को अक्षम कैसे करें क्लिक करें?

समस्या: मैं अगले/वापस बटन के क्लिक पर छवियों को लोड करने में सक्षम हूँ, लेकिन पिछले छवि तक पहुंचने के बाद, मैं वापस button.As उपयोगकर्ता पहले छवि पर है के लिए मेरे अगला बटन अक्षम और एक ही बनाना चाहते बैक बटन अक्षम होना चाहिए।

public class SequencerActivity extends Activity implements OnClickListener 
    { 
     private int imageCounter = 0; 
     private ImageView imageLoader; 

     private int[] imageList = {R.drawable.image_wo_lbl_0, R.drawable.image_wo_lbl_1, R.drawable.image_wo_lbl_2, R.drawable.image_wo_lbl_3, R.drawable.image_wo_lbl_4, R.drawable.image_wo_lbl_5, 
       R.drawable.image_wo_lbl_6, R.drawable.image_wo_lbl_8, R.drawable.image_wo_lbl_9,R.drawable.image_wo_lbl_10, R.drawable.image_wo_lbl_11}; 
     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      setContentView(R.layout.parent_frame);//this one is the common parent layout for all image views 
      super.onCreate(savedInstanceState); 

      /*requestWindowFeature(Window.FEATURE_NO_TITLE); 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN);*/ 

      //int image1 = R.drawable.image_w_lbl_0; 

      imageLoader = (ImageView) findViewById(R.id.imageLoader); 
      //imageLoader.setImageResource(image1); 

      ImageButton next = (ImageButton) findViewById(R.id.next); 
      ImageButton back = (ImageButton) findViewById(R.id.back); 
      next.setOnClickListener(this); 
      back.setOnClickListener(this); 
      //show the default image 
      this.loadImage(imageList[imageCounter]); 

     } 
     @Override 
     public void onClick(View v) 
     { 
      int imagePath = 0; 
      // TODO Auto-generated method stub 
      switch (v.getId()) 
      { 
      case R.id.next: 
       Log.i("Tag","tag"); 
       if(imageCounter < imageList.length) 
       { 
        imageCounter++; 
        imagePath = imageList[imageCounter]; 
        if (imageCounter==(imageList.length)-1) 
        { 
         //how to make my next button disable 

        } 
       } 
       break; 
      case R.id.back: 
       if(imageCounter > 0) 
       { 
        imageCounter--; 
        imagePath = imageList[imageCounter]; 
        if (imageCounter==0) 
        { 
         //how to make my back button disable 
        } 
       } 
       break; 
      } 
      this.loadImage(imagePath); 

     } 

     private void loadImage(int imagePath) 
     { 
      imageLoader.setImageResource(imagePath); 

     } 
    } 

उत्तर

14
case R.id.next: 
     Log.i("Tag","tag"); 
     if(imageCounter < imageList.length) 
     { 
      imageCounter++; 
      imagePath = imageList[imageCounter]; 
      if (imageCounter==(imageList.length)-1) 
      { 
       ImageButton next=(ImageButton)findViewBYId(R.id.next); 
       next.setEnabled(false); 
      } 
     } 
     break; 
    case R.id.back: 
     if(imageCounter > 0) 
     { 
      imageCounter--; 
      imagePath = imageList[imageCounter]; 
      if (imageCounter==0) 
      { 
       ImageButton back=(ImageButton)findViewBYId(r.id.back); 
       back.setEnabled(false); 
      } 
     } 
     break; 
+0

बहुत अच्छा काम किया !! और अब आवेदन – Alok

+0

kkkkkkkk पर चल रहा है यह अच्छा है ...... – viv

+2

किसी बिंदु पर बटन फिर से सक्षम नहीं होना चाहिए? – jul

8
next.setClickable(false); 
+0

मैं कोशिश की है उर कोड लेकिन इसमें त्रुटि है: आदिम प्रकार int पर setClickale (बूलियन) का आह्वान नहीं कर सकता। – Alok

+0

यह अजीब बात है, फ़ंक्शन को बूलियन की आवश्यकता होती है। इसे देखें: http://developer.android.com/reference/android/view/View.html। आप आवश्यक कार्यक्षमता के लिए Next.setEnabled (false) का भी उपयोग कर सकते हैं। –

+0

या तो वास्तव में मुझे क्लास वैरिएबल के रूप में अगली बार घोषित करना होगा या फिर मुझे मामले में वापस और अगले मामले में नया उदाहरण लेना होगा। आप विव उत्तर में देख सकते हैं कि उसने नया उदाहरण बनाया है। अब आवेदन चिकनी पर चल रहा है। और मैं कुछ नई कार्यक्षमताओं को शामिल करने वाला हूं। धन्यवाद – Alok

0

सिर्फ विकलांग दायाँ तीर के लिए अपने drawable फ़ोल्डर में दो अतिरिक्त छवियों और विकलांग बाएँ तीर के लिए एक डिस्क डालें: कोड के रूप में है।

अब कोशिश यह

  case R.id.next: 

     Log.i("Tag","tag"); 

      if(imageCounter < imageList.length) 


      { 
       imageCounter++; 

       imagePath = imageList[imageCounter]; 

       if (imageCounter==(imageList.length)-1) 

       { 


         //disabling right button by changing image from following code                             

         next.setImageDrawable(getResources().getDrawable(R.drawable.right_disabled)); 

       } 
      } 
      break; 
     case R.id.back: 

      if(imageCounter > 0) 

      { 
       imageCounter--; 

       imagePath = imageList[imageCounter]; 

       if (imageCounter==0) 

       { 
         back.setImageDrawable(getResources().getDrawable(R.drawable.left_disabled)); 
       } 
      } 
      break; 
4

अधिक पसंदीदा समाधान है,

onclick(){ 
    btn.setEnabled(false); 
    btn.setClickable(false); 
    //yourwork 
    myWork(); 
} 

myWork(){ 
//your tasks. 
btn.setEnabled(true); 
btn.setClickable(true); 
} 

एक कड़ी के रूप में आसानी से अनदेखा किया जा सकता है, मैं फिर से इस दोहराने के लिए किया था और फिर

संबंधित मुद्दे