One adapter for different adapter views - how to specify proper layout for the view?

by (Mishail) » Wed, 04 Mar 2009 23:50:13 GMT


Sponsored Links
 Greetings,

I want to re-use 1 adapter (similar to well known ImageAdapter from
samples) with 2 different views - Gallery and GridView.

I need to specify LayoutParams for the each View returned by getView()
method of my adapter. In case of Gallery it should be instance of
Gallery.LayoutParams, and in case of GridView it should be
GridView.LayoutParams. I'll get an exception for sure if I'll try
Gallery.LayoutParams with GridView and vice versa.

What is the best way to do that? Can I somehow use "parent" parameter
(ViewGroup parent) for that?

--~--~---------~--~----~------------~-------~--~----~



One adapter for different adapter views - how to specify proper layout for the view?

by (Mishail) » Thu, 05 Mar 2009 20:59:07 GMT


 Up thread.

I believe it should be trivial. Just stick my nose into the
appropriate docs
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Picture.createFromStream loses dashed line

Hi everyone,

I want to draw a dashed line in Android.
I know I can achieve it using Paint#setPathEffect.
When I simply get the picture object, I can draw a dashed line wihtout
any problem.

However, for speed, I get a ByteArrayOutputStream
from the Picture object and get another Pciture.
This method almost works correctly, but it seems to lose the dashed
line style.
Here is the sample code to reproduce it.

---

import java.io.*;

import android.app.Activity;
import android.content.Context;
import android.graphics.*;
import android.os.Bundle;
import android.view.View;

public class DashBugActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new DashBugView(this));
  }
}

class DashBugView extends View {
  DashBugView(Context context) {
    super(context);
  }

  protected void onDraw(Canvas canvas) {
    int w = getWidth();
    int h = getHeight();
    Paint paint = new Paint();
    paint.setColor(-1);
    canvas.drawRect(0, 0, w, h, paint);

    Picture picture = createPicture();
    picture.draw(canvas);
  }

  static Picture createPicture() {
    Picture picture = new Picture();
    Canvas canvas = picture.beginRecording(100, 100);
    Paint paint = new Paint();
    paint.setStrokeWidth(8);
    paint.setPathEffect(new DashPathEffect(new float[] {
        8, 8
    }, 0));
    canvas.drawLine(0, 0, 100, 100, paint);
    picture.endRecording();

    if (false) {
      // Picture draws dash correctly.
      return picture;
    } else {
      // Export and Import bytes, and picture draws solid line !
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      picture.writeToStream(baos);
      byte[] pictureBytes = baos.toByteArray();
      Picture picture2 = Picture.createFromStream(new
ByteArrayInputStream(pictureBytes));
      return picture2;
    }
  }
}
---

The sample code above does not draw the dashed line. However,
if I change from "if(false)" to "if(true)", then I could get the
correct result.
Does anyone know the work-around to avoid it?


-- 

2. RatingBar adding new background artifacts in 2.3

Is anyone else noticing their RatingBar skins looking really bad once
they port to 2.3?

I'm seeing the toggle button(i believe) as the background skin on all
my rating bar's that have their style inherit from @android:style/
Widget.RatingBar.Small. I've checked the 2.3(9) source styles and
don't see anything out of the ordinary.

Also, how to get rid of this background skin would be greatly
appreciated as I'm still fighting with it at the moment. :)

Thanks,
Rob

-- 

3. screen light off problem

4. Anyone able to use ENCODING_PCM_8BIT in recording and playing sound?

5. Service or no service

6. disable the search key android alertdialog

7. Sipdroid build problem