开发者

setContentView over and setting ImageView force close

So basically the screen has a GridView with 9 images on it. When one of those images clicks I have it setContentView to open a layout of just an image view so it displays the chosen image. After they are done with that image they will click back and it gets rid of that conten开发者_JS百科tView and displays the GridView again. The majority of that works except for it using the ImageView in the other contentView.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setView();
    setContentView(R.layout.wall);


    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
       @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long arg3) {
            pos = position;
            displayWallpaper();


        }
    });
}

private void displayWallpaper(){
        switch(pos){
        case 0: 
            setContentView(R.layout.wallpaper);
            viewing=true;
        ImageView image1 = (ImageView)findViewById(R.id.display);
        rotate(R.drawable.wallpaper1, image1);
            break;
}
}

So the force close is happening at the ImageView line. And my guess is it isn't finding display, but display is in the wallpaper layout. Any ideas why it may be force closing. If you need more info let me know what and if you have a better way of doing what I am trying to make happen let me know. Thanks.

Also just tested it out. So far the force close still happens if rotate() is commented out and ImageView is there. If I comment both out it works fine (apart from displaying the image).


Your Image View image1 was not existing in the layout you specifed i.e in display layout...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜