在我的代码中,我只使用了两个listview和两个CustomAdapter用于这两个listView,其中第一个listview是通过CustomAdapter实现的,从此CustomAdapter我只想调用另一个(Activity/Other对于第二个列表视图定制适配器)。它提供了异常像从customadapter调用其他Activity/CustomAdapter
java.lang.IllegalStateException: 系统服务不提供给 活动的onCreate()之前
private LayoutInflater mInflater;
ViewFlipper vfWall;
ImageView ivComments;
TextView tvComments;
ListView lvComments;
WallCustom2 adapterForComments;
ImageDownloader imageDownloader = new ImageDownloader();
private static final String[] URLS =
{
"http://lh5.ggpht.com/_mrb7w4gF8Ds/TCpetKSqM1I/AAAAAAAAD2c/Qef6Gsqf12Y/s144-c/_DSC4374%20copy.jpg",
};
String[] itms={"hey dude kya kar raha hai.........."};
public WallCustom(Context context,ViewFlipper vfWall,ImageView ivComments,TextView tvComments,ListView lvComments)
{
this.ivComments=ivComments;
this.tvComments=tvComments;
this.lvComments=lvComments;
this.mInflater = LayoutInflater.from(context);
this.vfWall=vfWall;
}
public int getCount()
{
return URLS.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.wallcustom, null);
holder = new ViewHolder();
holder.Image = (ImageView) convertView.findViewById(R.id.ivImageWallCustom);
holder.Message= (TextView) convertView.findViewById(R.id.tvMessageWallCustom);
holder.comments= (TextView) convertView.findViewById(R.id.tvExtraWallCustom);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
if(imageDownloader.download(URLS[position],holder.Image)!=null)
{
holder.Image.setImageBitmap(imageDownloader.download(URLS[position],holder.Image));
}
holder.Message.setText("hey dude kya kar raha hai..........");
holder.comments.setText("Comments ");
holder.comments.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(imageDownloader.download(URLS[position],ivComments)!=null)
{
ivComments.setImageBitmap(imageDownloader.download(URLS[position],ivComments));
}
tvComments.setText(itms[position]);
Wall wallobj=new Wall();
adapterForComments=wallobj.ListViewForComments(); // gives object of second custom adapter
lvComments.setAdapter(adapterForComments); // lvComments my second list view in which i want to set second custom adapter
vfWall.showNext();
}
});
return convertView;
}
class ViewHolder
{
ImageView Image;
TextView Message;
TextView comments;
}
发布自定义适配器的代码。 – 2011-02-11 13:12:30