我在做什麼? 我有這個加載了一個XML的片段。在該XML內我有一個圖像按鈕,它應該顯示一個對話框消息。Android支持庫v4對話框片段
這是片段的代碼;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class LoadingupFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View v = inflater.inflate(R.layout.example, container, false);
return v;
}
public void dialogboxalert (View view){
ExampleAlert dialog = new ExampleAlert();
// dialog.show(getSupportFragmentManager(),""); ERRRORRR
}
這是對話框的代碼;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
public class ExampleAlert extends android.support.v4.app.DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("This is my dialog..").setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
return dialog;
}
}
請問有人可以幫我解決支持庫問題嗎?發生
發表您的日誌貓 – 2015-03-03 11:59:49
也許你的ExampleAlert對話框擴展爲android.app.DialogFragement。它應該執行ansdorid.support.v4.app.DialogFragment – 2015-03-03 12:01:24
這是給我的錯誤線「// dialog.show(getSupportFragmentManager(),」「); ERRRORRR」..錯誤是「無法解析方法」show( android.support.v4.app.FragmentManager.java.lang.String)'「 – 2015-03-03 12:02:44