我有一个活动包含使用片段的3个标签.我想在标签移动时加载/更改工具栏菜单.
public class SpendsFragment extends Fragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MenuItem menuInicio = menu.add(0, 0, 0, "Início");
menuInicio.setIcon(android.R.drawable.ic_menu_edit);
MenuItem menuBusca = menu.add(1, 1, 0, "Buscar");
menuBusca.setIcon(android.R.drawable.ic_menu_search);
setHasOptionsMenu(true);
super.onCreateOptionsMenu(menu, inflater);
}
}
public class MoneyFragment extends Fragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MenuItem menuInicio = menu.add(0, 0, 0, "Edit");
menuInicio.setIcon(R.drawable.xyz);
MenuItem menuBusca = menu.add(1, 1, 0, "Delete");
menuBusca.setIcon(R.drawable.abc);
setHasOptionsMenu(true);
super.onCreateOptionsMenu(menu, inflater);
}
}
Run Code Online (Sandbox Code Playgroud) 以下是我从android下载文件的android代码.
private String executeMultipart_download(String uri, String filepath)
throws SocketTimeoutException, IOException {
int count;
System.setProperty("http.keepAlive", "false");
// uri="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTzoeDGx78aM1InBnPLNb1209jyc2Ck0cRG9x113SalI9FsPiMXyrts4fdU";
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
int lenghtOfFile = connection.getContentLength();
Log.d("File Download", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(filepath);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
output.write(data, 0, count); …Run Code Online (Sandbox Code Playgroud) 在Flutter(Android)中
我在Flutter应用中有两个TextFormField。当我按下后退按钮。这些文本字段正在空白。
class FirstScreen extends StatelessWidget {
TextEditingController charectorsController = new TextEditingController();
TextEditingController lengthCntroller = new TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Center(
child: Container(
margin: EdgeInsets.all(8),
child: SingleChildScrollView(
child: Column(
children: [
myEditText(charectorsController, "Enter charectors Word"),
myEditText(lengthCntroller, "Word length"),
RaisedButton(
child: Text('Launch screen'),
onPressed: () {
// Navigate to the second screen using a named route
// Navigator.pushNamed(context, '/second');
print("Rahul");
readFile();
},
)
],
),
)),
),
);
}
} …Run Code Online (Sandbox Code Playgroud)