Android《第一行代码》项目实战之酷我天气阅读笔记

ProgressDialog 使用方法

progressDialog=new ProgressDialog(context);
progressDialog.setMessage(“正在加载”);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
progressDialog.dismiss();关闭

捕获back按键

重写onBackPressed()方法即可

强转数组为字符串

方法一:String.valueOf(char[] data) : 将 char 数组 data 转换成字符串
方法二:New String(char[] data)

处理数据库并发问题

/**
* 获取weatherDB实例
*/
public synchronized static WeatherDB getInstance(Context context){
if (weatherDB==null) {
weatherDB=new WeatherDB(context);
}
return weatherDB;
}

在主程序中调用这个代码:
WeatherDB weatherDB = WeatherDB.getInstance(this);
静态方法在程序执行比较早,在活动创建好以后再初始化这个数据库实例

防止硬编码

通过调用接口方式,代替硬编码,以防写错

public interface PlaceType {
public final static String province=”province”;
public final static String city=”city”;
public final static String county=”county”;
}

调用方法:String type = PlaceType.province
防止在多次保存在sharedpreference中填错其名值对中的名,造成一些难以察觉到的困扰

在SQLite数据库中建表语句规范

/**
 * city表建表语句
 */
public static final String CREATE_CITY="create table city ("
         +"id integer primary key autoincrement,"
         +"city_name text,"
         +"city_code text," 
         +"province_id integer)";

为弹出菜单设置透明背景

Drawable transpent = new ColorDrawable(Color.TRANSPARENT);
mPopupWindow.setBackgroundDrawable(transpent);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Python代码示例,用于爬取我音乐的歌曲信息: ```python import requests from bs4 import BeautifulSoup # 设置请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} # 输入歌曲名称 song_name = input('请输入歌曲名称:') # 搜索歌曲,获取搜索结果页面 url = 'http://www.kuwo.cn/search/list?key=' + song_name res = requests.get(url, headers=headers).text soup = BeautifulSoup(res, 'html.parser') # 获取第一首歌曲的ID song_id = soup.select('.listMusic > li > div > a')[0]['href'].split('/')[-1] # 获取歌曲信息页面 url = 'http://www.kuwo.cn/play_detail/' + song_id res = requests.get(url, headers=headers).text soup = BeautifulSoup(res, 'html.parser') # 获取歌曲信息 song_name = soup.select('.songName > h1')[0].text artist_name = soup.select('.artistName > a')[0].text album_name = soup.select('.albumName > a')[0].text lyrics = soup.select('.lrcContent')[0].text # 输出歌曲信息 print('歌曲名称:', song_name) print('歌手名称:', artist_name) print('专辑名称:', album_name) print('歌词:\n', lyrics) ``` 这个代码示例可以让你输入歌曲名称,然后爬取我音乐的搜索结果页面,从中获取第一首歌曲的ID,然后爬取歌曲信息页面,从中获取歌曲的名称、歌手、专辑和歌词等信息。请注意,这个代码示例只是一个简单的例子,如果你要爬取更多的数据,需要更复杂的代码。同时,请注意爬虫道德规范,不要随意爬取他人网站的数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值