Called other Activity/CustomAdapter from an customadapter
In my code i just used two listview and two CustomAdapter for this two listView,in which first listview is implement through an CustomAdapter,from this CustomAdapter i just want to call another (Activity/Other custom Adapter for second listview).It gives Exception like
java.lang.IllegalStateException: System services not available to Activities before 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;
}
java.lang.IllegalStateException: System services not available to Activities before onCreate()
That error message is fairly straight-forward. You are attempting to use a system service, such as LayoutInflater
, from the constructor or initializer of an activity. Do not attempt to use LayoutInflater
until onCreate()
at the earliest.
You might be using systemServide(InflaterService) that cannot be use untill the oncreate() event is called. So the console error message is straight to understand.
精彩评论