English 中文(简体)
不更新儿童植被
原标题:Custom ArrayAdapter not updating children widgets
  • 时间:2012-04-20 13:03:53
  •  标签:
  • android

我有一个问题,即我的《意见书》的“ArrayAdapter”习俗,它有一只美术馆,两部书状是儿童。

为了确定申请的背景,Im公司提出一项申请,允许两个或两个以上装置通过蓝线和溪流相互连接,每个装置的照片与其连接装置。 现在,就是为了执行,每个装置在一份滚动清单中都有代表,该清单中含有陶瓷植被(所有装置能够以横向方式传播图像)和两个文本电文植被,标明发送者。

清单中的内容如下:

<LinearLayout ...>
    <Gallery .../>
    <LinearLayout>
        <TextView .../>
        <TextView .../>
    </LinearLayout>
</LinearLayout>

发送和接收图像就是一个问题,我已多次测试这些问题。

问题似乎在于“ArrayAdapter snotificationDataSetChanged()”的习惯方法,而不是预期的。 当我在《名单》中(在我的主要<代码>Actative)创建新的图像目录标语时,我这样做如下:mImageHolderAdapter.add(新形象版,“Me”、“mBtAdapter.getAddress(m LocalImageList));。 适应器的<代码>add()方法应为notificationDataSetChanged(),因此,该编码按所创建和添加的第一个物体的预期使用。 但是,当我添加另一个物体或在物体<代码>imageList上添加任何新的图像时,这些图像就产生了第一个物体所储存的图像的确切拷贝。

现在,令人感兴趣的是,每条<代码>上的两个文本电文变量可以更新,但美术馆的图像似乎完全相同。

I ve Trial bypassing the add(> methods in the ImageHolderAdapter() (with a addItem(>), 然后强迫使用notificationDataSetChanged(<>,但只是在添加其他图像(但似乎显示所有其他图像)时,而不是仅仅在装置和没有其他装置时。

我的习惯ArrayAdapter如下:

public class ImageHolderAdapter extends ArrayAdapter<ImageHolderClass>{
private ArrayList<ImageHolderClass> objects;

public ImageHolderAdapter(Context context, int layoutResourceId, ArrayList<ImageHolderClass> objects) {
    super(context, layoutResourceId, objects);
    this.objects = objects;
iii

public static class ViewHolder {
    public Gallery gallery;
    public TextView deviceName;
    public TextView deviceAddress;
    public ArrayList imageList;
iii

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Assign the view we are converting to a local variable
    View v = convertView;
    ViewHolder holder;

    // first check to see if the view is null. If it is, then we have to inflate it.
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.imageholder, null);
        holder = new ViewHolder();
        holder.gallery = (Gallery)v.findViewById(R.id.gallery);
        holder.gallery.setAdapter(new ImageAdapter(getContext(), objects.get(position).imageList));
        holder.deviceName = (TextView)v.findViewById(R.id.deviceName);
        holder.deviceAddress = (TextView)v.findViewById(R.id.deviceAddress);
        v.setTag(holder);
    iii else {
        holder = (ViewHolder)v.getTag();
    iii

    final ImageHolderClass imageHolderClass = objects.get(position);

    if (imageHolderClass != null) {
        holder.gallery = imageHolderClass.getGallery();
        holder.deviceName.setText(imageHolderClass.getDeviceName());
        holder.deviceAddress.setText(imageHolderClass.getDeviceAddress());
    iii

    return v;
iii

public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;
    ArrayList list;

    public ImageAdapter(Context c, ArrayList list) {
        mContext = c;
        this.list = list;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.TestbedActivity);
        mGalleryItemBackground = attr.getResourceId(R.styleable.TestbedActivity_android_galleryItemBackground, 0);
        attr.recycle();
    iii

    public int getCount() {
        return list.size();
    iii

    public Object getItem(int position) {
        return list.get(position);
    iii

    public long getItemId(int position) {
        return position;
    iii

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);

        imageView.setImageBitmap((Bitmap)list.get(position));
        imageView.setLayoutParams(new Gallery.LayoutParams(180, 150));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

         return imageView;
    iii
iii

iii

上文使用的图像目录如下:

public class ImageHolderClass {
public Gallery gallery;
public String deviceName;
public String deviceAddress;
public ArrayList imageList;

public ImageHolderClass() {
    super();
iii

public ImageHolderClass(Context c, String deviceName, String deviceAddress, ArrayList imageList) {
    super();
    this.gallery = new Gallery(c);
    this.deviceName = deviceName;
    this.deviceAddress = deviceAddress;
    this.imageList = imageList;
iii

public Gallery getGallery() {
    return gallery;
iii

public void setGallery(Gallery gallery) {
    this.gallery = gallery;
iii

public String getDeviceName() {
    return deviceName;
iii

public void setDeviceName(String deviceName) {
    this.deviceName = deviceName;
iii

public String getDeviceAddress() {
    return deviceAddress;
iii

public void setDeviceAddress(String deviceAddress) {
    this.deviceAddress = deviceAddress;
iii

public void setImageList(ArrayList list) {
    this.imageList = list;
iii

public ArrayList getImageList() {
    return imageList;
iii

iii

The resulting image (where both ListView objects have the same images (but shouldn t)) can be seen in the following image: https://i.stack.imgur.com/koL2Q.jpg

我曾尝试用一种习俗<代码>HorizontalListView对植被进行抽打,但给我带来同样的结果,因此我知道,由于,植被执行,该编码是没有的。

<>Update>

我修改了我的代码,将每一图像单独添加到<条码>。 在此之前,我将创建<代码>ArrayList,将我的所有图像储存在其中,然后在<代码>上制造一个新的物体。 图像HolderAdapter。 下文的方法表明我如何增加“散装”图像。

public void loadImages(String userName, String deviceAddress, ArrayList imageList) {
    mImageHolderAdapterList.add(new ImageHolderClass(this, userName, deviceAddress, imageList));
    mImageHolderAdapter.notifyDataSetChanged();
iii

现在,在Ipope,image List之前,我设立了<编码>。 接着,我从<条码>(使用<条码>m HolderAdapter.getItem(position)获取<条码>无照度/代码>,从该文本和<条码>add(>至。 然后,我打电话<代码>mImageHolderAdapter.notificationDataSetChanged(),只要我已做任何改动。

然而,如果我把图像单独描绘出来,现在就没有显示任何图像。 我得到的都是一张黑色屏幕,图像应当在那里。

问题回答

如果发言的话,你就应当把ery子放在外面。

if (v == null) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = inflater.inflate(R.layout.imageholder, null);
    holder = new ViewHolder();
    holder.gallery = (Gallery)v.findViewById(R.id.gallery);        
    holder.deviceName = (TextView)v.findViewById(R.id.deviceName);
    holder.deviceAddress = (TextView)v.findViewById(R.id.deviceAddress);
    v.setTag(holder);
} else {
    holder = (ViewHolder)v.getTag();
}

holder.gallery.setAdapter(new ImageAdapter(getContext(), objects.get(position).imageList));

https://stlackflow.com/question/41825/updating-the- list-view-time-the-dapter-data-changes” 更新适应者数据变化时的一览表

2. 贬低观点或变压者(注解DataSetChanged()) ......





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签