我在我的应用程序中使用导航选项卡.我有3个片段从Internet上加载不同的数据.我想知道在哪里放置发出HTTP请求的代码的最佳位置onCreate,onCreateView或者onActivityCreated?
通常,我将所有代码(请求数据,填充适配器,膨胀视图...)放入onCreateView.我也看到很多人在互联网上这样做.
但是这个指南https://github.com/thecodepath/android_guides/wiki/Creating-and-Using-Fragments以不同的方式做事.所以我想确定要做什么.
我正在开发Google Apps脚本,我想将URL参数拉入HTML文件.例如,如果用户访问my_domain.com/?hello=test,则HTML输出应为"Hello test".这是我的代码.
的index.html
<html>
<body><p>Hello <?= data ?></p></body>
</html>
Run Code Online (Sandbox Code Playgroud)
myCode.gs
function doGet(e) {
var t = HtmlService.createHtmlOutputFromFile('index');
t.data = e.parameter.hello;
return t.evaluate();
}
Run Code Online (Sandbox Code Playgroud)
这会导致错误消息:"Vous ne pouvez pas ajouter ni modifierdepropriétéspourcet objet." (您无法添加或修改此对象的属性.)
我不知道为什么.我按照此文档https://developers.google.com/apps-script/html_service他们说:
模板访问数据的第三种方法是直接在脚本文件中向模板添加变量,如下例所示.
function doGet() {
var t = HtmlService.createTemplateFromFile('myTemplate');
t.data = SpreadsheetApp.openById('SPREADSHEET_KEY_GOES_HERE').getRangeByName('dataRange').getValues();
return t.evaluate();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Contextual Action Barwith ListView(CHOICE MODE SINGLE).一切正常但我不知道如何检索所选项目.
listViewData.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listViewData.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (mActionMode != null) {
return false;
}
mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(mActionModeCallback);
view.setSelected(true);
return true;
}
});
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem …Run Code Online (Sandbox Code Playgroud)