📄 singleweatherinfoview.java
字号:
package com.yarin.android.CityWeather;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SingleWeatherInfoView extends LinearLayout
{
private ImageView myWeatherImageView = null;
private TextView myTempTextView = null;
public SingleWeatherInfoView(Context context)
{
super(context);
}
public SingleWeatherInfoView(Context context, AttributeSet attrs)
{
super(context, attrs);
this.myWeatherImageView = new ImageView(context);
this.myWeatherImageView.setPadding(10, 5, 5, 5);
this.myTempTextView = new TextView(context);
this.myTempTextView.setTextColor(R.color.black);
this.myTempTextView.setTextSize(16);
this.addView(this.myWeatherImageView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
this.addView(this.myTempTextView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
public void setWeatherString(String aWeatherString)
{
this.myTempTextView.setText(aWeatherString);
}
public void setWeatherIcon(URL aURL){
try{
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
this.myWeatherImageView.setImageBitmap(bm);
}catch (Exception e){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -