0
我試圖從我的片段傳遞一些信息到我的適配器來顯示一個ListView,它確實通過,但ListView在完成加載後不顯示任何東西。 我在下面附加了我的CustomAdapter類。爲什麼我無法在android中查看我的Listview?
package com.example.rama.hello.Adapters;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.rama.hello.Bean.RowItem;
import com.example.rama.hello.R;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by RAMA on 10/25/2016.
*/
public class CustomAdapter extends ArrayAdapter<RowItem> {
Context mcontext;
ArrayList<RowItem> rowItem = new ArrayList<RowItem>();
private RowItem row;
RowItem data;
public CustomAdapter(Context context, int resourceId,
ArrayList<RowItem> items) {
super(context, resourceId, items);
this.mcontext = context;
}
@Override
public int getCount()
{
return rowItem.size();
}
@Override
public long getItemId(int position) {
return rowItem.indexOf(getItem(position));
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater mInflater = (LayoutInflater) mcontext
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_item,parent,false);
}
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
TextView txtSubTitle = (TextView) convertView.findViewById(R.id.sub_title);
TextView txtRightTitle = (TextView) convertView.findViewById(R.id.right_title);
RowItem row_pos = getItem(position);
// setting the image resource and title,subtitle,Righttitle
File imgFile = new File(row_pos.getIcon());
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imgIcon.setImageBitmap(myBitmap);
}
if(row_pos.getTitle() == " ")
txtTitle.setText(row_pos.getPhone_number());
else
txtTitle.setText(row_pos.getTitle());
txtSubTitle.setText(row_pos.getSub_title());
txtRightTitle.setText(row_pos.getRight_title());
return convertView;
}
}
讓我們保留與澄清帖子相關的評論而不是相關討論。謝謝。 –