目前我沒有太多的片段體驗,所以我希望任何人都可以幫助我!一些一個月前,應用程序釋放細粒編譯之前,現在我有這個問題片段中的默認構造函數
Android Studio中說: 「問題避免碎片不是默認的構造函數。」
我希望有人能幫助我在這裏解決這個問題。
public static class TagClickDialog extends DialogFragment {
private final TagClickDialogListener mListener;
private final Context mContext;
private final Tag[] mTags;
public TagClickDialog(Context context, TagClickDialogListener listener, Tag[] tags) {
mListener = listener;
mContext = context;
mTags = tags;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String[] dialogItems = new String[mTags.length];
for (int i=0; i<mTags.length; i++) {
dialogItems[i] = mTags[i].getValue();
}
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(getResources().getString(R.string.tags))
.setItems(dialogItems, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
mListener.onTagClick(mTags[which]);
}
});
return builder.create();
}
}
可能的重複[爲什麼我要避免片段中的非默認構造函數?](http://stackoverflow.com/questions/12062946/why-do-i-want-to-avoid-non-default-constructors-in-fragments) –
您使用Intents將活動內容發送到活動。要將東西發送到片段中,請使用Bundle。檢查出Pramod的答案。 – rafid059