0

i'm very much a beginner with programming.. but i'm trying to develop a small android app using monodroid to store contacts in and call contacts from the address book.

Please forgive me if this is very simple but i have a text field and a button, both of which are in my Resources XML file and i want to be able to CLEAR the text in the textbox by clicking the button which will obviously be called 'Clear'.. all help is much appreciated as i'm looking forward to learning more.

4

2 回答 2

0

假设您有以下布局,我假设它与您已经拥有的类似:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:id="@+id/TextField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/Clear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Clear"/>
</LinearLayout>

然后在您的活动代码中,您可以执行以下操作:

var clear = FindViewById<Button>(Resource.Id.Clear);
var textField = FindViewById<TextView>(Resource.Id.TextField);

clear.Click += (src, args) =>
               {
                   textField.Text = "";
               };
于 2013-01-22T22:12:40.807 回答
0

这个怎么样?

  Button ClearText=(Button) findViewById(R.id.ClearText);
  ClearText.setOnClickListener(new View.OnClickListener(){
  public void onClick(View v){
    EditText textedit=(EditText) findViewById(R.id.textedit);
    textedit.setText("");
  }
 });

clear 必须像这样在布局文件中注册为按钮的 onclick 处理程序

   <ImageButton android:id="@+id/ClearText"
    android:text="@string/ClearText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    **android:onClick="clear"**          
    android:src="@drawable/clear"
    />
于 2013-01-22T20:22:48.957 回答