题目内容

简述用RecyclerView来做相册列表展示的的使用步骤?

查看答案
更多问题

请说出服务(Service)在两种启动模式下的生命周期

1、编写程序,使用HTTP请求中Get请求获取百度(http://www.baidu.com)首页信息,发送get请求,将网页以流的形式读回来。public class HttpGetActivity extends AppCompatActivity {private TextView tvData;private URL url;// 在下文用 new 方法创建,传入百度网址private HttpURLConnection conn; // 在下文@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_httpget);//获取文本组件对象,通过调用findViewById(int id),组件id为R.id.tvData(1)______________________________________________________//对线程 thread 成员变量调用 start()方法来启动线程(2)______________________________________________________}Thread thread = new Thread(new Runnable() {@Overridepublic void run() {try {//创建url对象,参数为”https://www.baidu.com”(3)______________________________________________// 调用 url的 openConnection()方法打开一个HttpURLConnection连接(4)______________________________________________//设置请求方式get请求,可以不设置,因为默认就是Get请求conn.setRequestMethod(“GET”);// 设置连接主机超时时间conn.setConnectTimeout(5000);// 设置从主机读取数据超时间conn.setReadTimeout(5000);//调用 connect()方法,建立了与服务器的连接(5)________________________________________________// 判断请求是否成功 ,成功码为200if (200 == conn.getResponseCode()) {//获得输入流,HttpURLConnection调用getInputStream()方法后get请求才发出去。InputStream inputStream = conn.getInputStream();//把字节流InputStream 转化成字符流 InputStreamReader(6)_________________________________________________________//把字符流InputStremReader转换成缓冲字符流BufferedReader(7)__________________________________________________________// 创建一个StringBuffer对象result(8)__________________________________________________________String str = "";while ((str = br.readLine()) != null) {//result调用append()方法将str添加到result中(9)________________________________________________ }runOnUiThread(new Runnable() {@Overridepublic void run() {//将result显示到文本组件上,文本对象调用setText()方法实现(10)_____________________________________________ }});}else{Toast.makeText(HttpGetActivity.this,"请求失败",Toast.LENGTH_SHORT).show();}} catch (Exception e) {e.printStackTrace();}}});}

1. 使用SharedPreferences实现数据存储,存储的数据包括,姓名(name),性别(sex),年龄(age),根据 以下提供的基础代码,完成以下功能:添加数据:张三,男,30; 删除key为name的数据,清空数据。public class SPActivity extends AppCompatActivity implements View.OnClickListener {private Button btnAdd, btnDelete, btnClear;private TextView tvData;private SharedPreferences sp;private SharedPreferences.Editor editor;private String name;private int age;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_sp);btnAdd = (Button) findViewById(R.id.btn_Add);btnDelete = (Button) findViewById(R.id.btn_Delete);btnClear = (Button) findViewById(R.id.btn_Clear); btnClear.setOnClickListener(this);tvData = (TextView) findViewById(R.id.tvData); btnAdd.setOnClickListener(this);// 实例化SharedPreferences,文件名为 MyFile ,模式为 Context.MODE_PRIVATE(1) ____________________________________________________________// 得到 Editor对象(2) ____________________________________________________________}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.btn_Add://editor 调用 putString添加键为name,值为张三的数据(3) __________________________________________________// editor 调用 putString添加键为 sex,值为 男的数据(4)___________________________________________________// editor 调用 pubInt 添加键为 age,值为30的数据(5)___________________________________________________// editor 调用 apply() 方法提交 数据(6) __________________________________________________name = sp.getString("name", "default");age = sp.getInt("age", 0);// 将姓名,年龄在文本组件 tvData上,调用 setText()方法显示(7) __________________________________________________break;case R.id.btn_Delete:// editor 调用 remove() 方法删除值为name的值(8) __________________________________________________editor.remove("age");editor.apply();name = sp.getString("name", "default");age = sp.getInt("age", 0);break;case R.id.btn_Clear:// editor 调用 clear()方法清空数据(9)___________________________________________________editor.apply();if (name.equals("default") && age == 0) {// 文件组件tvData上显示无数据(10) _____________________________________________}break;}}}

常用的水闸底板型式有 和。

答案查题题库