Android gridview中的图像在emulator中显示,但在设备中不显示
我有一个图像gridView,我正在使用url中的图像 它在模拟器中正常工作,但图像不会显示在设备中。日志中没有错误。下面是我尝试过的代码Android gridview中的图像在emulator中显示,但在设备中不显示,android,Android,我有一个图像gridView,我正在使用url中的图像 它在模拟器中正常工作,但图像不会显示在设备中。日志中没有错误。下面是我尝试过的代码 public class Home extends Fragment implements TabHost.OnTabChangeListener, OnClickListener { TabHost tabHost; View vi; StaggeredAdapter adapter; TextView t
public class Home extends Fragment implements TabHost.OnTabChangeListener,
OnClickListener {
TabHost tabHost;
View vi;
StaggeredAdapter adapter;
TextView tv;
public String urls[] = {
"http://farm9.staticflickr.com/8462/8005636463_0cb4ea6be2.jpg",
"http://farm8.staticflickr.com/7232/6913504132_a0fce67a0e_c.jpg",
"http://farm5.staticflickr.com/4133/5096108108_df62764fcc_b.jpg",
"http://farm5.staticflickr.com/4074/4789681330_2e30dfcacb_b.jpg",
"http://farm9.staticflickr.com/8208/8219397252_a04e2184b2.jpg",
"http://farm9.staticflickr.com/8483/8218023445_02037c8fda.jpg",
"http://farm9.staticflickr.com/8335/8144074340_38a4c622ab.jpg",
"http://farm9.staticflickr.com/8060/8173387478_a117990661.jpg",
"http://farm9.staticflickr.com/8056/8144042175_28c3564cd3.jpg",
"http://farm9.staticflickr.com/8183/8088373701_c9281fc202.jpg",
"http://farm9.staticflickr.com/8185/8081514424_270630b7a5.jpg",
"http://farm9.staticflickr.com/8462/8005636463_0cb4ea6be2.jpg",
"http://farm9.staticflickr.com/8306/7987149886_6535bf7055.jpg",
"http://farm9.staticflickr.com/8444/7947923460_18ffdce3a5.jpg",
"http://farm9.staticflickr.com/8182/7941954368_3c88ba4a28.jpg",
"http://farm9.staticflickr.com/8304/7832284992_244762c43d.jpg",
"http://farm9.staticflickr.com/8163/7709112696_3c7149a90a.jpg",
"http://farm8.staticflickr.com/7127/7675112872_e92b1dbe35.jpg",
"http://farm8.staticflickr.com/7111/7429651528_a23ebb0b8c.jpg",
"http://farm9.staticflickr.com/8288/7525381378_aa2917fa0e.jpg",
"http://farm6.staticflickr.com/5336/7384863678_5ef87814fe.jpg",
"http://farm8.staticflickr.com/7102/7179457127_36e1cbaab7.jpg",
"http://farm8.staticflickr.com/7086/7238812536_1334d78c05.jpg",
"http://farm8.staticflickr.com/7243/7193236466_33a37765a4.jpg",
"http://farm8.staticflickr.com/7251/7059629417_e0e96a4c46.jpg",
"http://farm8.staticflickr.com/7084/6885444694_6272874cfc.jpg" };
public static final String ARG_SECTION_NUMBER = "section_number";
public StaggeredGridView PremiumgridView;
public StaggeredGridView FeaturedgridView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
vi = inflater.inflate(R.layout.home, container, false);
Button iv = (Button) vi.findViewById(R.id.btnMoreDialog);
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu homepopup = new PopupMenu(getActivity(), v);
MenuInflater inflater = homepopup.getMenuInflater();
inflater.inflate(R.menu.moredialog, homepopup.getMenu());
homepopup.show();
}
});
PremiumgridView = (StaggeredGridView) vi.findViewById(R.id.premiumstaggeredGridView);
new Dialogs().execute(urls);
return vi;
}
private class Dialogs extends AsyncTask<String[], Void, String[]> {
@Override
protected String[] doInBackground(String[]... params) {
return params[0];
}
protected void onPostExecute(String[] result) {
Log.d("url", result[0]);
String new_string = result[0].replaceAll("http://", "www.");
Log.d("urls", new_string);
// Premium Dialog
int premiummargin = getResources().getDimensionPixelSize(R.dimen.margin);
PremiumgridView.setItemMargin(premiummargin);
PremiumgridView.setPadding(premiummargin, 0, premiummargin, 0);
StaggeredAdapter premiumadapter = new StaggeredAdapter(vi.getContext(),
R.id.photoimageview, result, R.layout.row_staggered_demo);
PremiumgridView.setAdapter(premiumadapter);
premiumadapter.notifyDataSetChanged();
}
@Override
protected void onPreExecute() {
// nothing to do
}
}
}
公共类Home扩展片段实现TabHost.OnTabChangeListener,
onclick侦听器{
TabHost-TabHost;
视图六;
交错适配器;
文本视图电视;
公共字符串URL[]={
"http://farm9.staticflickr.com/8462/8005636463_0cb4ea6be2.jpg",
"http://farm8.staticflickr.com/7232/6913504132_a0fce67a0e_c.jpg",
"http://farm5.staticflickr.com/4133/5096108108_df62764fcc_b.jpg",
"http://farm5.staticflickr.com/4074/4789681330_2e30dfcacb_b.jpg",
"http://farm9.staticflickr.com/8208/8219397252_a04e2184b2.jpg",
"http://farm9.staticflickr.com/8483/8218023445_02037c8fda.jpg",
"http://farm9.staticflickr.com/8335/8144074340_38a4c622ab.jpg",
"http://farm9.staticflickr.com/8060/8173387478_a117990661.jpg",
"http://farm9.staticflickr.com/8056/8144042175_28c3564cd3.jpg",
"http://farm9.staticflickr.com/8183/8088373701_c9281fc202.jpg",
"http://farm9.staticflickr.com/8185/8081514424_270630b7a5.jpg",
"http://farm9.staticflickr.com/8462/8005636463_0cb4ea6be2.jpg",
"http://farm9.staticflickr.com/8306/7987149886_6535bf7055.jpg",
"http://farm9.staticflickr.com/8444/7947923460_18ffdce3a5.jpg",
"http://farm9.staticflickr.com/8182/7941954368_3c88ba4a28.jpg",
"http://farm9.staticflickr.com/8304/7832284992_244762c43d.jpg",
"http://farm9.staticflickr.com/8163/7709112696_3c7149a90a.jpg",
"http://farm8.staticflickr.com/7127/7675112872_e92b1dbe35.jpg",
"http://farm8.staticflickr.com/7111/7429651528_a23ebb0b8c.jpg",
"http://farm9.staticflickr.com/8288/7525381378_aa2917fa0e.jpg",
"http://farm6.staticflickr.com/5336/7384863678_5ef87814fe.jpg",
"http://farm8.staticflickr.com/7102/7179457127_36e1cbaab7.jpg",
"http://farm8.staticflickr.com/7086/7238812536_1334d78c05.jpg",
"http://farm8.staticflickr.com/7243/7193236466_33a37765a4.jpg",
"http://farm8.staticflickr.com/7251/7059629417_e0e96a4c46.jpg",
"http://farm8.staticflickr.com/7084/6885444694_6272874cfc.jpg" };
公共静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”;
公共视图PremiumgridView;
公共侧视图功能侧视图;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
vi=充气机。充气(R.布局图.主,容器,假);
按钮iv=(按钮)vi.findViewById(R.id.btnMoreDialog);
iv.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
PopupMenu homepopup=新的PopupMenu(getActivity(),v);
MenuInflater充气器=homepopup.getMenuInflater();
充气器。充气(R.menu.moredilog,homepopup.getMenu());
homepopup.show();
}
});
PremiumgridView=(StaggedGridView)vi.findViewById(R.id.premiumstaggeredGridView);
新对话框().execute(URL);
返回vi;
}
私有类对话框扩展了异步任务{
@凌驾
受保护的字符串[]doInBackground(字符串[]…参数){
返回参数[0];
}
受保护的void onPostExecute(字符串[]结果){
Log.d(“url”,结果[0]);
String new_String=result[0].replaceAll(“http://”、“www.”);
Log.d(“URL”,新字符串);
//高级对话框
int premiummargin=getResources().getDimensionPixelSize(R.dimen.margin);
PremiumgridView.setItemMargin(premiummargin);
setPadding(premiummargin,0,premiummargin,0);
StaggeredAdapter premiumadapter=新的StaggeredAdapter(vi.getContext(),
R.id.photoimageview、结果、R.layout.row\u交错\u demo);
setAdapter(premiumadapter);
premiumadapter.notifyDataSetChanged();
}
@凌驾
受保护的void onPreExecute(){
//无事可做
}
}
}
我的适配器类
staggedAdapter.java
public class StaggeredAdapter extends ArrayAdapter<String> implements
OnClickListener {
private ImageLoader mLoader;
private int _row;
private Context _context;
public StaggeredAdapter(Context context, int textViewResourceId,
String[] objects, int row) {
super(context, textViewResourceId, objects);
_context = context;
mLoader = new ImageLoader(context);
_row = row;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater layoutInflator = LayoutInflater.from(getContext());
convertView = layoutInflator.inflate(R.layout.row_staggered_demo, null);
holder = new ViewHolder();
holder.imageView = (ScaleImageView) convertView
.findViewById(R.id.photoimageview);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
mLoader.DisplayImage(getItem(position), holder.imageView);
return convertView;
}
static class ViewHolder {
ScaleImageView imageView;
LinearLayout view;
}
public void onClick(View v) {
Toast.makeText(_context, "buffering......... please wait...",
Toast.LENGTH_LONG).show();
}
}
公共类交错适配器扩展了ArrayAdapter实现
onclick侦听器{
专用图像装载机;
私人国际路权;
私人语境(private Context)(私人语境);;
公共交错适配器(上下文,int textViewResourceId,
字符串[]对象,int行){
超级(上下文、textViewResourceId、对象);
_上下文=上下文;
mLoader=新的图像加载器(上下文);
_行=行;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
LayoutInflater layoutInflator=LayoutInflater.from(getContext());
convertView=LayoutFlator.充气(R.layout.row\u交错\u演示,空);
holder=新的ViewHolder();
holder.imageView=(ScaleImageView)convertView
.findViewById(R.id.photoimageview);
convertView.setTag(支架);
}
holder=(ViewHolder)convertView.getTag();
mLoader.DisplayImage(getItem(位置)、holder.imageView);
返回视图;
}
静态类视窗夹{
ScaleImageView图像视图;
线性布局视图;
}
公共void onClick(视图v){
Toast.makeText(_上下文,“缓冲…”请稍候,
Toast.LENGTH_LONG).show();
}
}
有什么想法或建议吗
谢谢,检查设备上的可用空间
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />