0

私はプログラミングの初心者ですが、monodroidを使用して連絡先を保存し、名簿から連絡先に電話をかける小さなAndroidアプリを開発しようとしています。

これが非常に単純な場合はご容赦ください。ただし、テキストフィールドとボタンがあります。どちらもリソースXMLファイルにあり、明らかに呼び出されるボタンをクリックしてテキストボックスのテキストをクリアできるようにしたいです。明確な'..私はもっと学ぶことを楽しみにしているので、すべての助けは大いに感謝されます。

4

2 に答える 2

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 に答える
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 に答える