Listview
大小爲10個項目。直到它不顯示Listview
中的任何內容。我在上面的適配器中添加了Item of List,但無法獲得單行的Listview
。任何人都請幫我解決我在適配器中的錯誤?Listview display nothing
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import bughunters.tashfik.chooseapp.Model.Category;
import bughunters.tashfik.chooseapp.Model.Comment;
import bughunters.tashfik.chooseapp.R;
public class CommentViewAdapter extends BaseAdapter {
private Context context;
private List<Comment> messagesItems;
// public static List<String> imagelist;
public CommentViewAdapter(Context context, List<Comment> navDrawerItems) {
Toast.makeText(context,"Sixe ids"+String.valueOf(navDrawerItems.size()),Toast.LENGTH_LONG).show();
this.context = context;
this.messagesItems = navDrawerItems;
}
@Override
public int getCount() {
return messagesItems.size();
}
@Override
public Object getItem(int position) {
return messagesItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.comments_list_item, null);
TextView textViewProfileName = (TextView) convertView.findViewById(R.id.textViewProfileName);
TextView textViewMesssage = (TextView) convertView.findViewById(R.id.textViewMesssage);
TextView textViewTime = (TextView) convertView.findViewById(R.id.textViewTime);
Toast.makeText(context,messagesItems.get(position).getUsername(),Toast.LENGTH_LONG).show();
ImageView imageViewUserProfilePic = (ImageView) convertView.findViewById(R.id.imageViewUserProfilePic);
textViewProfileName.setText(messagesItems.get(position).getUsername());
textViewMesssage.setText(messagesItems.get(position).getMessage());
textViewTime.setText(messagesItems.get(position).getTime());
return convertView;
}
}
你能也張貼comments_list_item.xml文件? –
你可以發佈MainActivity文件嗎? –
請發佈你的活動代碼 –