ในส่วนของ adapter function getView ให้เพิ่มการ เช็คว่า view ที่ส่งมาเป็น null หรือเปล่า ถ้าเป็น ให้ สร้างขึ้นมาใหม่ ถ้าไม่เป็นแสดงวง่ามีของเก่าอยู่ ในทำของเก่านั้นกลับมาใช้ใหม่ ดังโคดข้างล่าง
public View getView(int i, View view, ViewGroup viewGroup)
ClassItem item;
if(view != null)
{
item = (ClassItem) view;
}
else
{
item = new ClassItem(viewGroup.getContext());
}
return item;
Blog นี้ผมเขียนไว้อ่านเองกันลืมนะ อาจมีภาษา หรือ เนื้อหา ที่ไม่รู้เรื่อง sorry มามะ ที่นี้
วันเสาร์ที่ 6 สิงหาคม พ.ศ. 2559
วันอังคารที่ 2 สิงหาคม พ.ศ. 2559
Android Rule
- ห้ามใช้ Activity Context ใน Asynchronous Callback
- ต้องรู้เสมอว่าทำไมถึงใช้ Context นั้นๆ
วันจันทร์ที่ 1 สิงหาคม พ.ศ. 2559
Android: การแปลง object จาก json api ให้เป็นตัวแปรใน java
www.jsonshema2pojo.org
- Source type = JSON
- Annotation style = Gson
- Source type = JSON
- Annotation style = Gson
วันศุกร์ที่ 29 กรกฎาคม พ.ศ. 2559
วิธีการแสดง keyboard ใน Genymotion
วันเสาร์ที่ 16 เมษายน พ.ศ. 2559
Android การใช้ gilde แสดงผลแบบ วงกลม
Credit http://stackoverflow.com/questions/25278821/how-do-rounded-image-with-glide-library
มี 2 แบบ
1.
Glide.with(context).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
มี 2 แบบ
1.
Glide.with(context).load(url).asBitmap().centerCrop().into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
2Glide.with(this).load(URL).transform(new CircleTransform(context)).into(imageView);
public static class CircleTransform extends BitmapTransformation {
public CircleTransform(Context context) {
super(context);
}
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return circleCrop(pool, toTransform);
}
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
@Override public String getId() {
return getClass().getName();
}
}
วันเสาร์ที่ 28 พฤศจิกายน พ.ศ. 2558
C# การสร้าง form register พร้อมการ upload รูปภาพ
1. สร้าง Model รับข้อมูล
public class UserModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public HttpPostedFileBase File { get; set; }
}
2.สร้าง function รับค่าใน controller
public ActionResult Register(UserModel model)
{
if (model.File != null && model.File.ContentLength > 0)
{
var filename = Path.GetFileName(model.File.FileName);
var path = Path.Combine(Server.MapPath("~/content/pics"), filename);
model.File.SaveAs(path);
}
return RedirectToAction("Index");
}
3. สร้าง form ใน view
@using (Html.BeginForm("ชื่อฟังชัน", "ชื่อcontroller", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.LabelFor(m => m.FirstName)
@Html.TextBoxFor(m => m.FirstName)
@Html.LabelFor(m => m.LastName)
@Html.TextBoxFor(m => m.LastName)
<input type="file" name="file" />
<input type="submit" value="Search" />
}
public class UserModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public HttpPostedFileBase File { get; set; }
}
2.สร้าง function รับค่าใน controller
public ActionResult Register(UserModel model)
{
if (model.File != null && model.File.ContentLength > 0)
{
var filename = Path.GetFileName(model.File.FileName);
var path = Path.Combine(Server.MapPath("~/content/pics"), filename);
model.File.SaveAs(path);
}
return RedirectToAction("Index");
}
3. สร้าง form ใน view
@using (Html.BeginForm("ชื่อฟังชัน", "ชื่อcontroller", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.LabelFor(m => m.FirstName)
@Html.TextBoxFor(m => m.FirstName)
@Html.LabelFor(m => m.LastName)
@Html.TextBoxFor(m => m.LastName)
<input type="file" name="file" />
<input type="submit" value="Search" />
}
วิธีแก้ปัญหาการ upload file แล้วขึ้น error : Maximum request length exceeded.
ปัญหานี้เกิดจากการที่เรายังไม่ได้แก้คอนฟิกของเว็บให้รองรับการอับโหลดไฟล์ขนาดใหญ่ได้นั่นเอง
แก้โดยการไปที่ web.config แล้วเพิ่ม
แก้โดยการไปที่ web.config แล้วเพิ่ม
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
แค่นี้ก็จะเรียบร้อย
สมัครสมาชิก:
บทความ (Atom)