Android 在网格视图中使用url加载图像
我是android studio的新手。我想制作一个壁纸应用程序,在其中使用gridView中的图像url从internet加载图像。为此,我创建了活动\u common activty_common.xmlAndroid 在网格视图中使用url加载图像,android,Android,我是android studio的新手。我想制作一个壁纸应用程序,在其中使用gridView中的图像url从internet加载图像。为此,我创建了活动\u common activty_common.xml <GridView android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="100dp"
<GridView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="100dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:numColumns="2"
android:gravity="center"
android:stretchMode="columnWidth"
android:id="@+id/gridView" />
然后我创建了名为Food的java类
public class Food extends Activity {
public String[] mThumbIds = {
" https://www.pexels.com/photo/daylight-environment-fog-forest-539945/",
"https://www.pexels.com/photo/daylight-environment-fog-forest-539945/"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activtiy_common);
GridView gridView = (GridView) findViewById(R.id.gridView);
// Instance of ImageAdapter Class
gridView.setAdapter(new Gridadapter(this, mThumbIds));
}
}
我认为gridadapter允许整数[];
如何传递字符串[];
我添加了internet premissiona和毕加索图书馆
它给我的跑步应用程序是什么时候的错误:(28,29)错误:Gridadapter类中的构造函数Gridadapter无法应用于给定类型; 必需:上下文 发现:食物、字符串[] 原因:实际参数列表和正式参数列表长度不同
提前感谢您收到错误,因为在适配器类中Gridadapter中只有一个参数,您从活动中传递了两个参数 只需像这样更改Gridadapter构造函数
public Gridadapter(Context c,String[]Food) {
mContext = c;
mThumbIds=food;
}
你的适配器构造函数应该是
public Gridadapter(Context c,String[] mThumbIds) {
mContext = c;
mThumbIds = mThumbIds;
}
您在Gridadapter(这是mThumbIds)中传递了两个参数,但在适配器类中,您只定义了一个参数。 修改适配器类:
public Gridadapter(Context c,String mThumbIds[]) {
mContext = c;
this.mThumbIds[] = mThumbIds[];
}
在Food.java类中共享您的exceptiononly错误,代码在gridView.setAdapter(新Gridadapter(this,mThumbIds))下面;是的,只需更改适配器类中的构造函数,您的错误将得到解决此构造函数
public Gridadapter(Context c){mContext=c;}
my frienderror in only in Food.java classit的工作。但不幸的是,现在应用程序已停止,异常低于08-29 08:01:30.606 58-58/?W/Genyd:无法解析请求08-29 08:01:30.606 58-58/?W/Genyd:无法解析请求08-29 08:01:30.606 58-58/?W/Genyd:无法解析请求08-29 08:01:30.606 58-58/?W/Genyd:无法解析请求08-29 08:01:30.610 58-58/?W/Genyd:无法解析请求08-29 08:01:30.610 58-58/?W/Genyd:无法解析请求08-29 08:01:30.614 58-58/?W/Genyd:无法解析请求08-29 08:01:30.622 58-58/?W/Genyd:无法解析请求08-29 08:01:30.626 58-58/?W/Genyd:无法分析请求
public Gridadapter(Context c,String[] mThumbIds) {
mContext = c;
mThumbIds = mThumbIds;
}
public Gridadapter(Context c,String mThumbIds[]) {
mContext = c;
this.mThumbIds[] = mThumbIds[];
}