我試圖創建一個自定義編輯文字,結果被困在這裏了......錯誤通脹類(自定義視圖)
請參考下面
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public static class MyEditText1 extends EditText{
Paint mPaint;
public MyEditText1(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyEditText1(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint=new Paint();
mPaint.setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas c){
super.onDraw(c);
int height=getHeight();
int width=getWidth();
int linespace=10;
int count=height/linespace;
for(int i=0;i<count;i++){
c.drawLine(0, i*linespace, width, i*linespace, mPaint);
}
}
}
}
MyEditText類我的代碼是內部類
,我指的這個觀點在我的XML作爲
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.customedittext.MainActivity.MyEditText1
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:ems="10"
android:inputType="textNoSuggestions"/>
</RelativeLayout>
但應用越來越力CLOS編輯後立即開始。但當我保持內部類在MyEditText.java(並引用它在XML中)一個單獨的文件它工作得很好......保持它作爲內部類的問題是什麼......儘管我已經作出我的內部類是靜態的?
堆棧跟蹤丟失...... – WarrenFaith