Help with debugging Error in android custom component EditText
UPDATE
making the inner class 'static' fixed it
Please help me find out what the error is in the case below. I have a custom EditText inside an activity which implements the OnKeyListener. It is implemented as an inner class of the Activity
The reason i override plai开发者_开发知识库n TickerEditText to parent EditText is because in future i might modify EditText and also wanted to attach a OnKeyListener always to it.
I don't want to do this in Activity's onCreate().
Code compiles fine but I'm having runtime error when the application launches and inflates the view.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<view
class="com.example.android.ticker.TickerActivity$TickerEditText"
android:id="@+id/tickerText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Something !!"
/>
<com.example.android.ticker.customListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tickerListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/customListView"
android:scrollbars="vertical"
android:listSelector="@drawable/list_selector"
/>
</LinearLayout>
Usage public class TickerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ticker);
/** Get Reference to UI objects */
mTickerListView = (TickerListView)findViewById(R.id.tickerListView);
mTickerEditText = (EditText)findViewById(R.id.tickerText);
...
}
...
...
...
...
public class TickerEditText extends EditText implements OnKeyListener {
public TickerEditText(Context context) {
super(context);
}
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN)
if(keyCode == KeyEvent.KEYCODE_ENTER) {
//something
return true;
}
return false;
}
Thanks in advance
making the inner class 'static' fixed it
Also moved it as a separate class and called it using
精彩评论