BaseAdapterを使用してListViewにMap
の値を表示しようとしています。以下のコードを使用すると、すべての値をMap
に正常に印刷できます。しかし、私はのを使用してMap
という単一の値を表示する方法を知らない。ListViewでマップ値を表示する方法は?
MyContactAdapter2.javaは
public class MyContactAdapter2 extends BaseAdapter {
List<EffectList> contacts;
Context context;
private LayoutInflater mInflater;
// Constructors
public MyContactAdapter2(Context context, List<Map<String, List<EffectList>>> objects) {
this.context = context;
this.mInflater = LayoutInflater.from(context);
this.contacts = new ArrayList<>();
Map<String, List<EffectList>> map = objects.get(0);
Set<String> keySet = map.keySet();
Iterator<String> iterator = keySet.iterator();
while (iterator.hasNext()) {
this.contacts.addAll(map.get(iterator.next()));
}
}
@Override
public int getCount() {
int count = contacts.size();
return count;
}
@Override
public EffectList getItem(int position) {
return contacts.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final MyContactAdapter2.ViewHolder vh;
if (convertView == null) {
View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
vh = MyContactAdapter2.ViewHolder.create((RelativeLayout) view);
view.setTag(vh);
} else {
vh = (MyContactAdapter2.ViewHolder) convertView.getTag();
}
EffectList item = getItem(position);
vh.textViewName.setText(item.getEffectsId());
vh.textViewEmail.setText(item.getEffectsName());
return vh.rootView;
}
private static class ViewHolder {
public final RelativeLayout rootView;
public final ImageView imageView;
public final TextView textViewName;
public final TextView textViewEmail;
private ViewHolder(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
this.rootView = rootView;
this.imageView = imageView;
this.textViewName = textViewName;
this.textViewEmail = textViewEmail;
}
public static MyContactAdapter2.ViewHolder create(RelativeLayout rootView) {
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
return new MyContactAdapter2.ViewHolder(rootView, imageView, textViewName, textViewEmail);
}
}
}
これは私が
{
"effect_list": [{
"1":[
{
"effects_id":"1",
"effects_name":"Band 1"
},
{
"effects_id":"2",
"effects_name":"Band 2"
}
],
"2": [
{
"effects_id":"4",
"effects_name":"Background Blur"
},
{
"effects_id":"5",
"effects_name":"Blemish Removal"
}
]
}]
}
が、私は "1" ( "effects_id" の値のみを表示したい、解析する必要がJSONです:」 1 "、" effects_name ":" Band 1 "、" effects_id ":" 2 "、" effects_name ":" Band 2 ")。どうすれば達成できますか?
コンストラクタ内のコードと混同しています。あなたは、次のコード、
this.contacts = new ArrayList<>();
Map<String, List<EffectList>> map = objects.get(0);
Set<String> keySet = map.keySet();
Iterator<String> iterator = keySet.iterator();
while (iterator.hasNext()) {
this.contacts.addAll(map.get(iterator.next()));
EDIT
EffectList.java
public class EffectList {
@SerializedName("effects_id")
@Expose
private String effectsId;
@SerializedName("effects_name")
@Expose
private String effectsName;
public String getEffectsId() {
return effectsId;
}
/* public void setEffectsId(String effectsId) {
this.effectsId = effectsId;
}
*/
public String getEffectsName() {
return effectsName;
}
/*
public void setEffectsName(String effectsName) {
this.effectsName = effectsName;
}
*/
}
あなたもEffectListのソースコードを提供してもらえますか? – ZeusNet
@ ZeusNet、編集。 – user7357013