Question

I am using some code for a coverflow from the website,

http://www.inter-fuser.com/2010/01/android-coverflow-widget.html

normal working coverflow

this coverflow works great and no problems. however when I tried to put it inside of a xml layout it would not show up, only the black backgroud wallpaper for the coverflow showed up but the coverfow is missing.

missing coverflow in layout

the reason that I wanted put it inside of an xml layout is because of the need to put buttons on the bottom of the page. so I decided to make an xml layout with buttons on the lower part of the screen below the coverflow.

what is wrong or what am I missing that makes the coverflow not work inside of an xml layout?

there is probably something i am missing in my code for this to work. I did the following things to try and get this to work. the code author makes it look like all you have to do is use the included example code to set content view. and make a simple xml file in layouts and it should work.

i don't understand why the coverflow works so well by itself, and not work when placed inside of a layout.

is there a check list of things that are needed to be done for something like this to work?

the author for the coverflow code added the two commented out lines as a sample that can be used when you make your own cusom xml view

         //Use this if you want to use XML layout file
    //setContentView(R.layout.main);
    //coverFlow =  (CoverFlow) findViewById(R.id.coverflow);

I removed the comment out for these lines so I can use them.

next i added the following code to the xml layout

      <com.vagina.destruction.CoverFlow
        android:id="@+id/coverflow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
      </com.vagina.destruction.CoverFlow>

this is the error message i am getting from the visual layout editor in eclipse

The following classes could not be instantiated: - com.vagina.destructon.CoverFlow (Open Class, Show Error Log) - com.vagina.destruction.CoverFlowExample (Open Class, Show Error Log) See the Error Log (Window > Show View) for more details. Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse

and here is the part of the code at the start of the coverflow example activity

 public class CoverFlowExample extends Activity implements OnItemClickListener {
 /** Called when the activity is first created. */

int imageCount = 0;
Cursor cur;
String toastResult;
String pathName;
 ArrayList<String> list1 = new ArrayList<String>();
private int blocker = 0;
private int imagePosition;
private int pathIndex;
private int indexer;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CoverFlow coverFlow;
    coverFlow = new CoverFlow(this);

    Bundle extras = getIntent().getExtras();
    if(extras !=null) {

     imagePosition = extras.getInt("imagePosition");

    }


    String[] proj2 = {MediaStore.Images.Media.DATA};
    Cursor cur2 = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj2,  MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'", null, null);

    imageCount = cur2.getCount();


    cur2.close();

    coverFlow.setAdapter(new ImageAdapter(this));

    ImageAdapter coverImageAdapter =  new ImageAdapter(this);

    coverFlow.setAdapter(coverImageAdapter);

    coverFlow.setSpacing(-10);
    coverFlow.setSelection(imageCount, true);

 //  setContentView(coverFlow);

    coverFlow.setOnItemClickListener(this);

    coverFlow.setSelection(imagePosition);


    coverFlow =  (CoverFlow) findViewById(R.id.coverflow);

    //Use this if you want to use XML layout file
         setContentView(R.layout.activity_coverflow);
    coverFlow =  (CoverFlow) findViewById(R.id.coverflow);

    // centers the image on coverflow to the same image selected in the previous activity
      coverFlow.setBackgroundResource(R.drawable.blanklarge);
Was it helpful?

Solution

Use this

     public class CoverFlowExample extends Activity implements OnItemClickListener {
     /** Called when the activity is first created. */

    int imageCount = 0;
    Cursor cur;
    String toastResult;
    String pathName;
     ArrayList<String> list1 = new ArrayList<String>();
    private int blocker = 0;
    private int imagePosition;
    private int pathIndex;
    private int indexer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Use this if you want to use XML layout file
        setContentView(R.layout.activity_coverflow);
        CoverFlow coverFlow;
        coverFlow =  (CoverFlow) findViewById(R.id.coverflow);

/*        CoverFlow coverFlow;
        coverFlow = new CoverFlow(this); */

        Bundle extras = getIntent().getExtras();
        if(extras !=null) {

         imagePosition = extras.getInt("imagePosition");

        }


        String[] proj2 = {MediaStore.Images.Media.DATA};
        Cursor cur2 = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj2,  MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'", null, null);

        imageCount = cur2.getCount();


        cur2.close();

        coverFlow.setAdapter(new ImageAdapter(this));

        ImageAdapter coverImageAdapter =  new ImageAdapter(this);

        coverFlow.setAdapter(coverImageAdapter);

        coverFlow.setSpacing(-10);
        coverFlow.setSelection(imageCount, true);

        coverFlow.setOnItemClickListener(this);

        coverFlow.setSelection(imagePosition);



        // centers the image on coverflow to the same image selected in the previous activity
          coverFlow.setBackgroundResource(R.drawable.blanklarge);

basically the issue is that once you declare the things in xml, the opbjects are created automatically once you inflate them using setCOntentView. You can get those already created objects using findViewById and no need to create them again using "x = new x()"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top