I have created my ClearableEditText class, and created my clearable_edit_text.xml. I'm not sure how to change my main.xml to use the new compound control. I've searched a ton on how to use compound controls and I can't find anything. The API demo code doesn't seem to have real examples of compound controls either.
Any help would be appreciated.
My clearable_edit_text.xml
Code:
<?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">
<EditText android:layout_height="wrap_content" android:id="@+id/editText"
android:layout_width="fill_parent" />
<Button android:layout_height="wrap_content" android:text="Clear"
android:layout_width="fill_parent" android:id="@+id/clearButton" />
</LinearLayout>
My main.xml
Code:
<?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">
<EditText android:id="@+id/myEditText" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="New To Do Item" />
<ListView android:id="@+id/myListView" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
my ClearableEditText.java file
Code:
package com.paad.todolist;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class ClearableEditText extends LinearLayout {
EditText editText;
Button clearButton;
public ClearableEditText(Context context) {
super(context);
// inflate the view from the layout resource
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li;
li = (LayoutInflater) getContext().getSystemService(infService);
li.inflate(R.layout.clearable_edit_text, this, true);
// get references to the child controls
editText = (EditText) findViewById(R.id.editText);
clearButton = (Button) findViewById(R.id.clearButton);
hookupButton();
}
private void hookupButton() {
clearButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
editText.setText("");
}
});
}
public ClearableEditText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
}