이것은 어떻게 반복적으로 사용되도록 자체 클래스로 작성 될 수 있습니까? 그리고 코멘트 라인 "// Loads the List"가 어디에 있는지, 런타임에 변경할 수 있어야합니다.getExternalStorageState를 다시 사용하는 방법은 무엇입니까?
정보를 미리 기다리는 중입니다.
/**
* -- Check to See if the SD Card is Mounted & Loads the Ordered List
* ======================================================================
**/
private void storageState() {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
orderASC();// Loads the list
} else if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_UNMOUNTED)) {
Alerts.sdCardMissing(this);
}
}
개정 :
class StorageStateChecker {
static void storageState(Activity param, Listener l) {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
l.orderASC_Label();//Load the list by Label ASC
l.orderDSC_Label();
l.orderASC_Title();//Load the list by Title ASC
l.orderDSC_Title();
} else if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_UNMOUNTED)) {
// Pass context to AlertDialog.Builder
AlertDialog alertDialog = new AlertDialog.Builder(null).create();
alertDialog.setTitle("External Storage State");
alertDialog.setMessage("Your SD-Card is not mounted! If the device is plugged into a computer via the USB, please disconect the device.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//this.finish();
}
});
// alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
}
}
public interface Listener {
public void orderASC_Label();
public void orderDSC_Label();
public void orderASC_Title();
public void orderDSC_Title();
}
}
@LeffelMania/@Phil Lello Thnx 전화 코드를 사용합니다. Phil Lello의 방법을 사용하려고합니다. (이 자바에서는 안심할 수 있습니다 - Android newB). 위의 '개정 :'을 보면 올바른 생각을하고 있습니까? 또한 좀 더 자세한 예제/코드를 사용하여 Activity에서 호출을 더 확장 할 수 있습니까? 나는 아직 거기에 없다 - 내가가는대로 배우 라. 둘 다 고마워. J – CelticParser
Plz 내 프로필 4 왜 내가 여기에있는 이유. Thnx. – CelticParser
그러나 '새로운 AlertDialog.Builder (null) .create();'는'null'이있는 곳에서'param'을 전달해야합니다. 또한 StorageStateChecker를 Activity의 하위 클래스로 만들고 그 액티비티를 상속 받았다면 다소 모호한 설명으로 인해 정적 메서드/독립 실행 형 클래스 접근 방식을 사용했음을 언급해야합니다. –