package com.eternity;import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
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 {
private EditText editText;
private Button clearButton;
public ClearableEditText(Context context) {
super(context);
// 使用布局资源扩充视图
LayoutInflater li;
li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.clearable_edit_text, this, true);
editText = (EditText) findViewById(R.id.editText);
clearButton = (Button) findViewById(R.id.clearButton);
hookupButton();
}
public ClearableEditText(Context context, AttributeSet atts) {
super(context, atts);
//
// clearButton = (Button) findViewById(R.id.clearButton);
// hookupButton();
}
private void hookupButton() {
Log.w("w", "hookup");
clearButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.w("w", "click");
editText.setText("");
}
});
} }
目前可以运行。
但是把:
// clearButton = (Button) findViewById(R.id.clearButton);
// hookupButton();
注释去掉之后,就不能运行,抛InflateException。请问是为什么啊?
解决方案 »
- androidGridView --九宫格显示问题
- 求助,在一个activity里面设置 自动跳转到下一个activity的方法!
- Android模拟器 插拔卡命令
- 关于ExpandableListView,请教各路大神!!!
- android2.2建立数据库content provider和android1.6有区别吗?
- 如何检测多个指头scroll
- 如何部署android服务器端的java代码
- xmpp 连接不上服务器
- AndRoid客户端怎样加载服务器盘符下的图片文件
- glsurfaceview removeview然后addview 导致黑屏或绿屏
- 怎么将二进制转为图片并显示在程序上呢。新手 急!!!!!!!在线等
- 关于android系统运行纯java的讨论
LayoutInflater li;
li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.clearable_edit_text, this, true);
正如ls所说,你应该先为其指定一个View