2013-06-25 53 views
0

我想在我的android记事本应用程序中显示内嵌的编辑文本,我在Activity中创建了linededittext类。但我无法在xml文件中设置视图。这是给android.view.inflateException,二进制XML文件的第17行充气类”如何在编辑文本Android中显示水平线?

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<com.android.sassypuma.todo.task.Add_Task.LinedEditText 
android:id="@+id/note" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/transparent" 
android:padding="5dip" 
android:scrollbars="vertical" 
android:fadingEdge="vertical" 
android:gravity="top" 
android:textSize="22sp" 
android:capitalize="sentences" 
/> 
</LinearLayout> 

活动在那里我使用LinedEditText类:

public class Add_Task extends Activity{ 

private EditText description; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.add_task); 
    description = (EditText)findViewById(R.id.note); 
} 

}

LinedEditText活动:

class LinedEditText extends EditText { 
private Rect mRect; 
private Paint mPaint; 

// we need this constructor for LayoutInflater 
public LinedEditText(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    init(); 
} 

public void init(){ 
     mRect = new Rect(); 
     mPaint = new Paint(); 
     mPaint.setStyle(Paint.Style.FILL_AND_STROKE); 
     mPaint.setColor(0xFF668800); //SET YOUR OWN COLOR HERE 
} 
@Override 
protected void onDraw(Canvas canvas) { 
    //int count = getLineCount(); 

    int height = getHeight(); 
    int line_height = getLineHeight(); 

    int count = height/line_height; 

    if (getLineCount() > count) 
     count = getLineCount();//for long text with scrolling 

    Rect r = mRect; 
    Paint paint = mPaint; 
    int baseline = getLineBounds(0, r);//first line 

    for (int i = 0; i < count; i++) { 

     canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, paint); 
     baseline += getLineHeight();//next line 
    } 

    super.onDraw(canvas); 
    } 
} 

请建议。tha nks ...

+0

任何人那里。 ..请建议 – Shweta

回答

0

您不使用视图作为标记名。您可以使用完全合格的类名

+0

我没有给你?请解释 – Shweta

+0
+0

对不起,我的帖子的一部分被堆栈溢出杀死。使用作为标记,而不是

0

在你的活动,你可以调用自定义的EditText您的自定义名称如下..

public class Add_Task extends Activity{ 

LinedEditText description; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.add_task); 
    description = (LinedEditText)findViewById(R.id.note); 
} 
} 

因此,它会工作

+0
+0

正确提及你的包名并检查。 – Harish

+0

请检查问题和所有的代码,它不工作。 – Shweta