定義適配器類只想提取JSON陣列
public class CustomListViewAdapter extends ArrayAdapter<Details> {
Context context;
String vid = "Video";
public CustomListViewAdapter(Context context, int resourceId,
List<Details> items) {
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
private class ViewHolder {
//ImageView textView;
TextView txtTitle;
TextView txtTitle2;
TextView txtDesc;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
//Details rowItem = (Details) getItem(position);
Details rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null || convertView.getTag() == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_item, null); //TODO: parent instead of null?
holder = new ViewHolder();
holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.txtTitle2 = (TextView) convertView.findViewById(R.id.link);
convertView.setTag(holder);
convertView.setTag(holder);
}
else if (rowItem.getResType().toString().equals(vid)){
holder = (ViewHolder) convertView.getTag();
}
holder.txtDesc.setText(rowItem.getResType());
holder.txtTitle.setText(rowItem.getName());
holder.txtTitle2.setText(rowItem.getUrl());
// holder.textView.setImageResource(rowItem.getImageId());
return convertView;
}}
我的代碼的特定對象的細節得到列表。
細節是我的getter和setter類JSON對象
ArrayList<Details> details;
private void aeroMethod(List<Details> mList) {
layout = (LinearLayout) findViewById(R.id.linear);
for (Details bean : details) {
if (bean.getResType().equals("Videos"))
//{if (bean.getResType().equalsIgnoreCase("Videos")) {
{
//nameList.add(bean.getResType());
ListView listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(this,
R.layout.list_item, mList);
listView.setAdapter(adapter);
}
}
}
在和適配器把if語句,但它不是working.My JSON是這樣
{
"results":[
{
"id":87,
"resType":"Notes",
"resLink":"upload/19/conserving our environment.pdf",
"resName":"Notes",
},
{
"id":88,
"resType":"Videos",
"resLink":"-ehD4H_ywyQ",
"resName":"Video",
},
{
"id":89,
"resType":"Videos",
"resLink":"-ehD4H_ywyQQ",
"resName":"Video",
},
因此,如果resType是視頻我希望所有的視頻內容意味着resLink,resName,ID
檢查[這個答案](http://stackoverflow.com/questions/17348453/parsing-youtube-gdata-json-into-listview) –
你可以發佈你在哪裏用JSON數據填充你的列表? –
我填充它們在fragment.So在我的listview中所有的內容都來了。我只想要那些滿足if條件if(bean.getResType()。equals(「Videos」))如上代碼 –