2012-01-06 18 views
9

संभव डुप्लिकेट बटन पर onclick:
Clear text in EditText when enterededittext कैसे साफ़ करें जब

डेटा जो जब बटन पर क्लिक गतिशील edittext को दिया जाता है कैसे साफ़ करें। मुझे कोड कैसे लिखना चाहिए? मुझे किस कार्य या विधि का उपयोग करना चाहिए? कृपया कोई भी ऐसा करने में मेरी सहायता कर सकता है?

+1

कोई भी डेटा दर्ज करने से पहले मुझे लगता है कि आप उपयोगकर्ता को कुछ संकेत देना चाहते हैं ?? क्या मैं सही हूँ? –

उत्तर

22

प्रयास करें

public void clear(View v) { 
    edittext.setText(""); 

} 

कहाँ clear onclick हैंडलर के रूप में बटन के लिए लेआउट फ़ाइल में इस

<ImageButton android:id="@+id/ClearButton" 
     android:text="@string/ClearButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="clear"   <<<--------here 
     android:src="@drawable/clear" 
    /> 
2

की तरह आप समारोह का उपयोग कर सकते

myEditText.setText(""); 
11
Button btn=(Button) findViewById(R.id.btn); 
btn.setOnClickListener(new View.OnClickListener(){ 
    public void onClick(View v){ 
     EditText et=(EditText) findViewById(R.id.et); 
     et.setText(""); 
    } 
}); 
2

रजिस्टर में पंजीकृत है bu के लिए एक ऑनक्लिक लिस्टनर टाटन जो संपादन टेक्स्ट में पाठ को हटा देता है। यह दस्तावेज़ वर्णन करता है कि यह कैसे करें: http://developer.android.com/guide/topics/ui/ui-events.html

श्रोता में पाठ को साफ़ करने के लिए बस एक खाली टेक्स्ट सेट करें: yourButton.setText ("");

2

यदि आपके बटन नाम है: rstBtn

& edittext क्षेत्र का नाम है: नाम

तो एक ऑनक्लिक ईवेंट हैंडलर सम्मिलित करें:

rstBtn.setOnClickListener(new OnClickListener() {   
public void onClick(View v){ 
      name.setText(""); 
     } 
    }); 
3

इसका सरल, मैं सिर्फ इतना है कि यू पर विचार कर रहा हूँ एक्सएमएल फाइल बनाने के बारे में जानें ... मैं इसके जावा भाग में डाल रहा हूं ....

public class StackOverFlow extends Activity{ 

    Button buttonToClick; 
    EditText editTextToclear; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    buttonToClick.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 

      editTextToclear.setText(""); 


     } 
    }); 
    } 

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