@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
final View rootView = inflater.inflate(R.layout.aa, container, false);
Firebase.setAndroidContext(getActivity());
Firebase ref = new Firebase(FIREBASE_URL);
title1=(TextView)rootView.findViewById(R.id.posttitle);
description1=(TextView)rootView.findViewById(R.id.postdesc);
image1=(ImageView)rootView.findViewById(R.id.postimage);
final List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
ListView listView = (ListView) rootView.findViewById(R.id.listView);
// Keys used in Hashmap
String[] from = {"title", "desc", "name"};
int[] to = {R.id.posttitle, R.id.postdesc, R.id.postdate};
final SimpleAdapter adapter = new SimpleAdapter(getActivity(), aList, R.layout.layoutarray, from, to);
listView.setAdapter(adapter);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
for (DataSnapshot single : child.getChildren()) {
Map<String, Object> map = (Map<String, Object>) single.getValue();
namerc = (String) map.get("Namerc");
String image = (String) map.get("Imagerc");//IMAGE URI
description = (String) map.get("Description");
title=(String) map.get("Title");
if (namerc!=null && description!=null && title!=null) {
String[] title1={title};
String[] desc1={description};
String[] name1={namerc};
Toast.makeText(getActivity(), description, Toast.LENGTH_SHORT).show();
for (int i=0;i<title1.length;i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("title", title1[i]);
hm.put("desc", desc1[i]);
hm.put("name", name1[i]);
aList.add(0,hm);
}
// Keys used in Hashmap
adapter.notifyDataSetChanged();
}
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
return rootView;
}
}
这是我的代码在这里我正在设置值并将其设置为listview但我无法将图像设置为listview。我可以设置它,请帮助我。 如何将图像uri设置为listview,这里我从数据库获取uri?
答案 0 :(得分:0)
在适配器的getView方法中,您可以像以下其他数据一样设置图像:
Picasso.with(context).load(uri).into(imageView);
你可以在.load()
中传递url或uri您可以按照以下教程创建适配器: listview