java - 用户数据到 ListView
问题描述
我正在使用 Parse,我正在尝试使用自定义适配器将所有用户数据从中检索到列表视图。列表视图目前正在处理假数据,我不知道如何使用我的真实数据。
我试图检索的数据是所有用户解析行:
用户名 | 细绳
企业名称 | 细绳
企业图片 | 位图
有多少人在做生意| 整数
listView 图片 - https://ibb.co/rZ7Qt95
列表视图代码:
String[] maintitle ={
"Title 1","Title 2",
"Title 3","Title 4",
"Title 5",
};
String[] subtitle ={
"Sub Title 1","Sub Title 2",
"Sub Title 3","Sub Title 4",
"Sub Title 5",
};
Integer[] imgid={
R.drawable.add,R.drawable.add,
R.drawable.add,R.drawable.add,
R.drawable.add,
};
自定义适配器代码:
class MyListAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] maintitle;
private final String[] subtitle;
private final Integer[] imgid;
public MyListAdapter(Activity context, String[] maintitle,String[] subtitle, Integer[] imgid) {
super(context, R.layout.mylist, maintitle);
// TODO Auto-generated constructor stub
this.context=context;
this.maintitle=maintitle;
this.subtitle=subtitle;
this.imgid=imgid;
}
public View getView(int position, View view, ViewGroup parent) {
View rowView = null;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.mylist, null,true);
TextView titleText = (TextView) rowView.findViewById(R.id.title);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
TextView subtitleText = (TextView) rowView.findViewById(R.id.subtitle);
titleText.setText(maintitle[position]);
imageView.setImageResource(imgid[position]);
subtitleText.setText(subtitle[position]);
}
return rowView;
}
}
我试图传递代码的用户数据:
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.orderByDescending("createdAt");
query.setLimit(20);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null){
for (ParseObject feed : objects){
Map<String, String> PlacesInfo = new HashMap<>();
PlacesInfo.put("username",feed.getString("username"));
PlacesInfo.put("businessname",feed.getString("BusinessName"));
PlacesInfo.put("peopleinbusiness",feed.getString("PeopleInBusiness"));
ParseFile postImage = feed.getParseFile("Pictures");
String imageUrl = postImage.getUrl() ; //live url
Uri imageUri = Uri.parse(imageUrl);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(FeedActivity.this.getContentResolver(), imageUri);
} catch (IOException ioException) {
ioException.printStackTrace();
}
feedData.add(PlacesInfo);
}
MyListAdapter adapter = new MyListAdapter(FeedActivity.this, maintitle, subtitle,imgid);
feedListView.setAdapter(adapter);
}
}
});
自定义 ListView XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp" />
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="10dp"/>
</LinearLayout>
</LinearLayout>
最终结果应该是一个 listView,其中包含来自 parse 的所有用户行数据。
欢迎任何帮助,谢谢!
解决方案
推荐阅读
- css - 未使用 nginx 在不同子域从 CSS 加载的图像
- java - JPA 查询元素集合
- apache-flink - 为 Flink DataStream 执行选择节点
- swift - 默认情况下,如何阻止 Xcode 倒置启动模拟器并启动景观?
- reactjs - ReactJS _ 文本编辑器 - 现有的 ReactJS 文本编辑器与 libreoffice 编辑器一样完整?
- python-3.x - 无法在 python 3 中导入 urllib.request 模块
- javascript - 如何使用 Leaflet 单独设置 GeoJSON GeometryCollection 的每个几何图形
- batch-file - 批处理文件 - 如果不是“选择 01”到“选择 99”转到 XXX?
- javascript - jQuery点击事件和settimeout
- java - 从图像视图打开菜单