Android学习之——APP番茄工作法——小结(2)
LayoutInflater inflater = getActivity().getLayoutInflater(); mMainView = inflater.inflate(R.layout.task_layout_main, (ViewGroup)getActivity().findViewById(R.id.viewpager), false);
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO 自动生成的方法存根 Log.i("MAIN", "^^^^^^^^TaskFragment^^^^^^^^onCreateView^^^^^^^^"); ViewGroup p = (ViewGroup) mMainView.getParent(); if (p != null) { p.removeAllViewsInLayout(); Log.i("MAIN", "^^^^^^^^TaskFragment^^^^^^^^removeAllViewsInLayout!!!!!!!!"); } return mMainView; }
package com.android.tomatotask.Task; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class SqliteHelper extends SQLiteOpenHelper { private static String INFONAME; private static String NAME; private static int VERSION = 1; static { NAME = " table_notepad"; INFONAME = "notepad.db"; } public SqliteHelper(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt) { super(paramContext, INFONAME, null, VERSION); } public void onCreate(SQLiteDatabase paramSQLiteDatabase) { paramSQLiteDatabase.execSQL("create table " + NAME + "(id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT)"); } public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2) { } }
package com.android.tomatotask.Task; import java.util.ArrayList; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class ChangeSqlite { public static String table = "table_notepad"; public long add(SQLiteDatabase paramSQLiteDatabase, Notepad paramNotepad) { ContentValues localContentValues = new ContentValues(); localContentValues.put("title", paramNotepad.getTitle()); long l = paramSQLiteDatabase.insert(table, null, localContentValues); paramSQLiteDatabase.close(); return l; } public void delete(SQLiteDatabase paramSQLiteDatabase, Notepad paramNotepad) { paramSQLiteDatabase.delete(table, "id=" + paramNotepad.getid(), null); paramSQLiteDatabase.close(); } public ArrayList<Notepad> query(SQLiteDatabase paramSQLiteDatabase) { ArrayList<Notepad> localArrayList = new ArrayList<Notepad>(); Cursor localCursor = paramSQLiteDatabase.query(table, new String[] { "id", "title" }, null, null, null, null, null); while (true) { if (!localCursor.moveToNext()) { paramSQLiteDatabase.close(); return localArrayList; } Notepad localNotepad = new Notepad(); localNotepad.setid(localCursor.getString(localCursor .getColumnIndex("id"))); localNotepad.setTitle(localCursor.getString(localCursor .getColumnIndex("title"))); localArrayList.add(localNotepad); } } public void update(SQLiteDatabase paramSQLiteDatabase, Notepad paramNotepad) { ContentValues localContentValues = new ContentValues(); localContentValues.put("title", paramNotepad.getTitle()); paramSQLiteDatabase.update(table, localContentValues, "id=" + paramNotepad.getid(), null); paramSQLiteDatabase.close(); } }
SQLiteDatabase localSqLiteDatabase = new SqliteHelper(getActivity(), null, null, 0).getWritableDatabase(); Notepad localNotepad = new Notepad();//自己定义的类 ChangeSqlite localChangeSqlite = new ChangeSqlite(); String strContent = editText.getText().toString(); if (strContent.equals("")) { Toast.makeText(getActivity(), "内容为空", Toast.LENGTH_SHORT).show(); } String strTitle=strContent.length()>11?" "+strContent.substring(0, 11):strContent; localNotepad.setContent(strContent); localNotepad.setTitle(strTitle); localNotepad.setdata(date); localChangeSqlite.add(localSqLiteDatabase, localNotepad);
package com.android.tomatotask.Task; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.TextView; public class DateLine extends TextView { private Paint ePaint = new Paint(); public DateLine(Context context) { super(context); // TODO 自动生成的构造函数存根 } public DateLine(Context context, AttributeSet attrs) { super(context, attrs); // TODO 自动生成的构造函数存根 this.ePaint.setColor(-16777216); this.ePaint.setStyle(Paint.Style.STROKE); } @Override protected void onDraw(Canvas canvas) { // TODO 自动生成的方法存根 canvas.drawLine(0.0F, 40.0F, getWidth(), 40.0F, this.ePaint); super.onDraw(canvas); } }
或者如下代码:
package com.android.tomatotask.Task; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.TextView; public class TextViewLine extends TextView { private Paint ePaint = new Paint(); public TextViewLine(Context context, AttributeSet attrs) { super(context, attrs); // TODO 自动生成的构造函数存根 this.ePaint.setColor(-16777216); this.ePaint.setStyle(Paint.Style.STROKE); } @Override protected void onDraw(Canvas canvas) { // TODO 自动生成的方法存根 super.onDraw(canvas); int i=getLineCount(); for (int j = 0; ; ++j) { if (j >= i) { super.onDraw(canvas); return; } float[] arrayOfFloat = new float[4]; arrayOfFloat[0] = 15.0F; arrayOfFloat[1] = ((j + 1) * getLineHeight()); arrayOfFloat[2] = (-20 + getWidth()); arrayOfFloat[3] = ((j + 1) * getLineHeight()); canvas.drawLines(arrayOfFloat, this.ePaint); } } }
package com.android.tomatotask.Task; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.EditText; public class DrawLine extends EditText { private Paint ePaint; // private Rect rect; public DrawLine(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub ePaint = new Paint(); // rect=new Rect(); ePaint.setColor(Color.BLACK); ePaint.setStyle(Paint.Style.STROKE); } // 标记3,此处线字交叉是由于行间距引起,注意使用getLineHeight()得到行高。 public void onDraw(Canvas canvas) { int count = getLineCount(); for (int i = 0; i < count + 11; i++) { float[] pts = { 15.0F, (i + 1) * getLineHeight(), this.getWidth() - 20.0F, (i + 1) * getLineHeight() }; // i*50-280,50增加则行间距大285增加则线靠上。 // canvas.drawLine(15, i*42, this.getWidth()-20,i*42, ePaint); canvas.drawLines(pts, ePaint); } super.onDraw(canvas); } }
<com.android.tomatotask.Task.DateLine android:textColor="#ffff0000" android:gravity="center" android:id="@id/editdate" android:background="@drawable/shapetop" android:layout_width="300.0dip" android:layout_height="30.0dip" android:layout_centerHorizontal="true" /> <com.android.tomatotask.Task.DrawLine android:textSize="18.0sp" android:textColor="#ff000000" android:gravity="top" android:id="@id/edittexttwo" android:background="@drawable/shape" android:scrollbars="vertical" android:layout_width="300.0dip" android:layout_height="100.0dip" android:layout_below="@id/editdate" android:layout_centerHorizontal="true" android:lineSpacingExtra="3.0dip" />
<com.android.tomatotask.Task.DateLine android:textColor="#ffff0000" android:gravity="center" android:id="@id/changedateview" android:background="@drawable/shapetop" android:layout_width="300.0dip" android:layout_height="27.0dip" android:layout_marginTop="8.0dip" android:layout_centerHorizontal="true" /> <com.android.tomatotask.Task.TextViewLine android:textSize="15.0sp" android:textColor="#ff000000" android:id="@id/changecontentview" android:background="@drawable/shape" android:layout_width="300.0dip" android:layout_height="wrap_content" android:minHeight="68.0dip" android:layout_below="@id/changedateview" android:layout_centerHorizontal="true" android:lineSpacingExtra="6.0dip" />
<style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:windowNoTitle">true</item> </style>
应用截图:
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。