1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-22 17:02:21 -05:00

Only enable the "Add" button when the alias input field is non-empty.

This commit is contained in:
Michael Imamura 2010-09-10 12:51:58 +08:00 committed by Sebastian Kaspari
parent 288a1a9093
commit 8c5af16b29
2 changed files with 20 additions and 3 deletions

View File

@ -22,12 +22,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text=""
android:layout_weight="1" />
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="Add" />
</LinearLayout>
<LinearLayout

View File

@ -10,6 +10,8 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
@ -20,11 +22,12 @@ import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class AddAliasActivity extends Activity implements OnClickListener, OnItemClickListener
public class AddAliasActivity extends Activity implements OnClickListener, OnItemClickListener, TextWatcher
{
private EditText aliasInput;
private ArrayAdapter<String> adapter;
private ArrayList<String> aliases;
private Button addButton;
private Button okButton;
@Override
@ -36,6 +39,7 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
setContentView(R.layout.aliasadd);
aliasInput = (EditText) findViewById(R.id.alias);
aliasInput.addTextChangedListener(this);
adapter = new ArrayAdapter<String>(this, R.layout.aliasitem);
@ -43,7 +47,8 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
list.setAdapter(adapter);
list.setOnItemClickListener(this);
((Button) findViewById(R.id.add)).setOnClickListener(this);
addButton = (Button) findViewById(R.id.add);
addButton.setOnClickListener(this);
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
okButton = (Button) findViewById(R.id.ok);
@ -109,4 +114,16 @@ public class AddAliasActivity extends Activity implements OnClickListener, OnIte
AlertDialog alert = builder.create();
alert.show();
}
public void afterTextChanged(Editable s) {
// Do nothing.
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing.
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
addButton.setEnabled(aliasInput.getText().length() > 0);
}
}