<< Android¡ÁLinearLayout¡Á | main | Android¡¡¡ÁAdapter¡Á >>

¥¹¥Ý¥ó¥µ¡¼¥µ¥¤¥È

°ìÄê´ü´Ö¹¹¿·¤¬¤Ê¤¤¤¿¤á¹­¹ð¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹


  • 2010.11.01 Monday
  • -
  • -
  • -
  • -
  • by ¥¹¥Ý¥ó¥µ¡¼¥É¥ê¥ó¥¯

Android¡Á³ÈÄ¥¥¦¥£¥¸¥Ã¥È­¡¡Á

 Android ÊÙ¶¯¿Ê¤ó¤Ç¤Þ¤¹¡£

¤ª»î¤·¥½¥Õ¥È¤È¤¤¤¦¤³¤È¤Ç¡¢²È·×Êíºî¤ê¤Þ¤·¤¿¡£

Æü¡¹ÆþÎϤ¹¤ë¥â¡¼¥É¤È¡¢·î¡¹¤Î¼ý»Ù¤ò°ìÍ÷¤Çɽ¼¨¤¹¤ë¤À¤±¤Î¤¤¤¿¤Ã¤Æ´Êñ¤Ê¥¢¥×¥ê¡£
ºÇ½é¤ÎÊÙ¶¯¤È¤·¤Æ¤Ï¡¢¤Ê¤«¤Ê¤«¤Î½ÐÍè¤Ç¤·¤¿¤¬¡¢¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤ò¤É¤¦ºî¤Ã¤¿¤é¤¤¤¤¤Î¤«·ë¹½¤Ê¤ä¤ß¤Þ¤·¤¿¡£

¥Ü¥¿¥ó²¡²¼»þ¤Î¥¤¥Ù¥ó¥È·Ï¤Î½èÍý¤Ç¤¹¤¬¡¢
¤É¤³¤Ç¤â»È¤¤¤½¤¦¤Ê¤â¤Î¤Ï¡¢Listener¥¯¥é¥¹¤òºîÀ®¤·¤Æ¤½¤Î¥¯¥é¥¹Æâ¤Ç½èÍý¤¹¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤¿¤Î¤Ç¤¹¤¬¡¢ÅÓÃæ¤ÇÈᤷ¤¤¤«¤Ê¥Ç¡¼¥¿¤Î¤ä¤ê¤È¤ê¤Ë¶ìÀ路¤Þ¤·¤¿¡£

À®¸ù¤·¤¿¤Î¤Ï¡¢³ÈÄ¥¥¦¥£¥¸¥Ã¥È¡£
¤È¤Ï¸À¤Ã¤Æ¤â¡¢¤¢¤Þ¤êµ¡Ç½¤ò»ý¤¿¤»¤¹¤®¤ë¤ÈÈÆÍÑÀ­¤¬¤Ê¤¯¤Ê¤ë¤Î¤Ç¡¢
EditText¤ò·Ñ¾µ¤·¤Æ¡¢¿ôÃÍÆþÎÏÍÑ¡¢ÆüÉÕÆþÎÏÍÑ¡¢Ê¸»úÎóÆþÎÏÍѤΥ¯¥é¥¹¤òºîÀ®¡£

³Æ¥¯¥é¥¹¤Ï¡¢abstract¤ÇÄêµÁ¤·¤¿¿Æ¥¯¥é¥¹¤ò·Ñ¾µ¤¹¤ë¤è¤¦¤Ë¤·¤Æ¡¢
ɬÍפ˱þ¤¸¤Æ»Ò¥¯¥é¥¹¤Ç¥×¥í¥Ñ¥Æ¥£¤òÄêµÁ¤¹¤ë¤è¤¦¤Ë¤·¤Æ¤Þ¤·¤¿¡£

¿Æ¥¯¥é¥¹¤Ï¤³¤ó¤Ê´¶¤¸¡¦¡¦¡¦

public abstract class AbstractEditText extends EditText {
/**
* ÆþÎÏ¥Á¥§¥Ã¥¯Íѥ᥽¥Ã¥É.<p>
* @return TRUE¡§À®¸ù/FALSE¡§¼ºÇÔ
*/
protected abstract boolean validator();

/**
* ¥³¥ó¥¹¥È¥é¥¯¥¿
* @param context
*/
public AbstractEditText(Context context) {
super(context);
}

/**
* ¥³¥ó¥¹¥È¥é¥¯¥¿
* @param context
* @param attrs
*/
public AbstractEditText(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context, attrs);
}

/**
* ¥Ó¥å¡¼¤Î½é´ü²½½èÍý
* @param context
* @param attrs
*/
private void initView(Context context, AttributeSet attrs) {
if (attrs != null) {
required = attrs.getAttributeBooleanValue(null, "required", false);
}
}

/**
* ɬ¿Ü¥Á¥§¥Ã¥¯¼Â»Ü²ÄÈÝ.
* <p>
*/
protected boolean required = false;

/**
* ɬ¿Ü¥Á¥§¥Ã¥¯¼Â»Ü²ÄÈÝ.
* <p>
* @return
*/
public boolean isRequired() {
return required;
}

/**
* ɬ¿Ü¥Á¥§¥Ã¥¯¼Â»Ü²ÄÈݤÎÀßÄê
* @param required
*            É¬¿Ü¥Á¥§¥Ã¥¯¼Â»Ü²ÄÈÝ
*/
public void setRequired(boolean required) {
this.required = required;
}
}

»Ò¥¯¥é¥¹¤Ï¤³¤ó¤Ê´¶¤¸¡¦¡¦¡¦

public class CharacterEdit extends AbstractEditText {

/**
* ¥³¥ó¥¹¥È¥é¥¯¥¿
* @param context
*/
public CharacterEdit(Context context) {
super(context);
}

/**
* ¥³¥ó¥¹¥È¥é¥¯¥¿
* @param context
* @param attrs
*/
public CharacterEdit(Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* ÆþÎÏ¥Á¥§¥Ã¥¯Íѥ᥽¥Ã¥É.
* <p>
* @return TRUE¡§À®¸ù/FALSE¡§¼ºÇÔ
*/
@Override
public boolean validator() {
boolean result = true;

// ɬ¿Ü¥Á¥§¥Ã¥¯
if (super.required) {
String target = super.getText().toString();
if (target == null || target.equals("")) {
this.setBackgroundColor(Color.RED);
result = false;
}
}
return result;
}

@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
if ( this.validator() ) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}
}

ÆüÉÕ¥¯¥é¥¹¤Ï¥Á¥§¥Ã¥¯½èÍý¤¬¤Þ¤À´Å¤¤¤Ç¤¹¤¬¡¦¡¦
¥¿¥Ã¥Á¥¤¥Ù¥ó¥È¤Ç¡¢DatePickerDialog¤òÍøÍѤ¹¤ë¤è¤¦¤Ë¤·¤Æ¤ß¤Æ¤Þ¤¹¡£

public class DateEdit extends AbstractEditText {

/**
 * ¥³¥ó¥¹¥È¥é¥¯¥¿
 * 
 * @param context
 */
public DateEdit(Context context) {
super(context);
}

/**
 * ¥³¥ó¥¹¥È¥é¥¯¥¿
 * 
 * @param context
 * @param attrs
 */
public DateEdit(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context, attrs);
}

/**
 * ¥Ó¥å¡¼¤Î½é´ü²½½èÍý
 * 
 * @param context
 * @param attrs
 */
private void initView(Context context, AttributeSet attrs) {
if (attrs != null) {
addSlash = attrs.getAttributeBooleanValue(null, "addslash", false);
}
this.setInputType(InputType.TYPE_DATETIME_VARIATION_DATE);

datePickerDialog = new DatePickerDialog(context,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
setText(year + "/" + monthOfYear + "/" + dayOfMonth);
}
}, Calendar.getInstance().get(Calendar.YEAR), Calendar
.getInstance().get(Calendar.MONTH) + 1, Calendar
.getInstance().get(Calendar.DAY_OF_MONTH));

}

private DatePickerDialog datePickerDialog = null;

@Override
public boolean onTouchEvent(MotionEvent event) {
if (datePickerDialog != null) {
datePickerDialog.show();
}
return super.onTouchEvent(event);
}

/**
 * ÆþÎÏ¥Á¥§¥Ã¥¯Íѥ᥽¥Ã¥É.
 * <p>
 * 
 * @return TRUE¡§À®¸ù/FALSE¡§¼ºÇÔ
 */
@Override
public boolean validator() {
boolean result = true;

// ɬ¿Ü¥Á¥§¥Ã¥¯
if (super.required) {
String target = super.getText().toString();
if (target == null || target.equals("")) {
this.setBackgroundColor(Color.RED);
result = false;
}
}
// ÆüÉÕÂÅÅöÀ­¥Á¥§¥Ã¥¯¤ò¼Â»Ü
EditText ymdEdit = (EditText)findViewById(R.id.daily_ymd);
String ymd = ymdEdit.getText().toString();
if (!ymd.equals("")) {
String[] ymds = ymd.split("/");
if (ymds.length == 3) {
int month = Integer.parseInt(ymds[1]);
int day = Integer.parseInt(ymds[2]);
if (!(month <= 12 && month >= 1)) {
ymdEdit.setBackgroundColor(Color.RED);
result = false;
}
if (!(day <= 31 && day >= 1)) {
ymdEdit.setBackgroundColor(Color.RED);
result = false;
}
} else {
ymdEdit.setBackgroundColor(Color.RED);
result = false;
}
} else {
ymdEdit.setBackgroundColor(Color.RED);
result = false;
}
return result;
}

/**
 * ¥Æ¥­¥¹¥È¥Ü¥Ã¥¯¥¹¤Ëʸ»úÎó¡Ê¥«¥ó¥ÞÊÔ½¸¡Ë¤òÀßÄꤹ¤ë
 * 
 * @param text
 */
public void setText(String date) {
if (date != null) {
if (this.addSlash) {
// ¥«¥ó¥ÞÊÔ½¸
super.setText(DateEdit.getDate(date));
} else {
super.setText(date);
}
}
}

/**
 * ÆüÉդΥե©¡¼¥Þ¥Ã¥È¤òÊÖ¤¹¡£
 * 
 * Setting - Date & Time - Select date format¤ÇÀßÄꤵ¤ì¤¿Ãͤò¼èÆÀ¤¹¤ë
 * 
 * @param ctx
 *            the application context
 * 
 * @return
 */
public static final String getDate(String date) {

final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";

Date inputDate = new Date(date);

SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT);

return formatter.format(inputDate);
}

/**
 * ¥¹¥é¥Ã¥·¥åÊÔ½¸²ÄÈÝ.
 * <p>
 */
private boolean addSlash = false;

public boolean isAddSlash() {
return addSlash;
}

public void setAddSlash(boolean addSlash) {
this.addSlash = addSlash;
}
}


»²¹Í¤Ë¤Ê¤ë¤Î¤«¡©¡Ê¾Ð¡Ë

Activity¤â¿Æ¥¯¥é¥¹¤òºîÀ®¤·¤Æ¡¢³ÈÄ¥¥¦¥£¥¸¥Ã¥È¤ò¼èÆÀ¤Ç¤­¤ë¤è¤¦¤Ë¥é¥Ã¥Ñ¡¼¥á¥½¥Ã¥É¤òÄêµÁ¤·¤Æ¤ß¤Þ¤·¤¿¡£
public class AbstractActivity extends Activity {

/**
* TAG.<p>
*/
protected String _TAG = "AbstractActivity";

/**
* NumberEdit¥¯¥é¥¹¤ò¼èÆÀ¤¹¤ë.<p>
* @param id ¥ê¥½¡¼¥¹ID
* @return NumberEdit¥¯¥é¥¹
*/
protected NumberEdit getNumberEdit(int id) {
NumberEdit result = null;
try {
result = (NumberEdit) findViewById(id);
} catch (ClassCastException ex) {
Log.v(_TAG, ex.getMessage());
}
return result;
}
/**
* DateEdit¥¯¥é¥¹¤ò¼èÆÀ¤¹¤ë.<p>
* @param id ¥ê¥½¡¼¥¹ID
* @return DateEdit¥¯¥é¥¹
*/
protected DateEdit getDateEdit(int id) {
DateEdit result = null;
try {
result = (DateEdit) findViewById(id);
} catch (ClassCastException ex) {
Log.v(_TAG, ex.getMessage());
}
return result;
}
/**
* CharacterEdit¥¯¥é¥¹¤ò¼èÆÀ¤¹¤ë.<p>
* @param id ¥ê¥½¡¼¥¹ID
* @return CharacterEdit¥¯¥é¥¹
*/
protected CharacterEdit getCharacterEdit(int id) {
CharacterEdit result = null;
try {
result = (CharacterEdit) findViewById(id);
} catch (ClassCastException ex) {
Log.v(_TAG, ex.getMessage());
}
return result;
}
}

²¿¤è¤ê¤â¡¢Adapter¥¯¥é¥¹ÊØÍø¤Ç¤¹¤Ê¡Ê¾Ð¡Ë



¥¹¥Ý¥ó¥µ¡¼¥µ¥¤¥È


  • 2010.11.01 Monday
  • -
  • 23:03
  • -
  • -
  • -
  • by ¥¹¥Ý¥ó¥µ¡¼¥É¥ê¥ó¥¯

¥³¥á¥ó¥È
¥³¥á¥ó¥È¤¹¤ë









¤³¤Îµ­»ö¤Î¥È¥é¥Ã¥¯¥Ð¥Ã¥¯URL
¥È¥é¥Ã¥¯¥Ð¥Ã¥¯
´ØÏ¢²ñ¼Ò
³ô¼°²ñ¼Ò¥Ä¥¯¥ë
À¿°Õ¤ÈÁϰդǵ»½Ñ¤ò¼Ò²ñ¤Ë³è¤«¤¹£É£Ô´ë¶È
      ¡¡¡¡¡¡¡¡
      ¡¡¡¡¡¡¡¡
»þ·×
calendar
     12
3456789
10111213141516
17181920212223
2425262728  
<< February 2019 >>
Amazon
selected entries
categories
archives
recent comment
recommend
links
profile
search this site.
sponsored links
others
mobile
qrcode
powered
̵ÎÁ¥Ö¥í¥°ºîÀ®¥µ¡¼¥Ó¥¹ JUGEM
2008JUGEM¥­¥ã¥é¥³¥ó¥°¥é¥ó¥×¥ê
¥­¥ã¥é¥¯¥¿¡¼¥Ç¥¶¥¤¥ó¡§°ëºêÍνõ/¡Ö¤ª¤·¤ã¤ì¤Ò¤Ä¤¸¡×