Android的禁用列表视图项目 [英] Android disable listview items

查看:109
本文介绍了Android的禁用列表视图项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我需要一些帮助或有问题的一些建议,我有。我从填充数据库我的列表视图,我需要检查时,我创造我的列表视图,如果该项目的ID在位置是一样的,从另外一个表中的id我的数据库。如果是,你可以单击该项目,如果不是我想要禁用它,但所有我发现怎么办that..I的信息不能真正了解如何做到这一点。

SO basically I need a little help or some suggestions with problem that I have. I'm populating my list view from database and I need to check when I'm creating my listview if the item's id on position is the same as the id from another table in my database. If it is, you can click that item, if not I want it to disable it, but all the information that I found about how to do that..I can't really understand how to do that.

import java.util.ArrayList;


import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

//For more information look at the bottom of file.

public class LazyAdapter extends BaseAdapter {


    private Activity activity;
    private String[] data;
    private ArrayList<String> name;
    private ArrayList<String> info;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;
    private Bitmap b;

    public LazyAdapter(Activity a, Bitmap d, ArrayList<String> names, ArrayList<String> information) {
        activity = a;
        b=d;
        name=names;
        info = information;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return name.size();
    }

    public Object getItem(int position) {
        return position;
    }

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

    public static class ViewHolder{
        public TextView name,info;
        public ImageView image;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        ViewHolder holder;
        if(convertView==null){
            vi = inflater.inflate(R.layout.item, null);
            holder=new ViewHolder();
            holder.name=(TextView)vi.findViewById(R.id.name);
            holder.info=(TextView)vi.findViewById(R.id.info);
            holder.image=(ImageView)vi.findViewById(R.id.image);
            vi.setTag(holder);
            Log.v("Position","Position : "+position);
        }
        else
            holder=(ViewHolder)vi.getTag();
            holder.name.setText(name.get(position));
            holder.info.setText(info.get(info.size()-1));

            //Here I must do a black magic and get the images if user had 'em.

            holder.image.setImageBitmap(b);

            //holder.image.setTag(data[position]);
            //imageLoader.DisplayImage(data[position], activity, holder.image);

            // Black magic over.
        return vi;
    }
}

任何意见或建议,如何做到这一点?

Any ideas or suggestions how to do that?

推荐答案

在适配器有一个方法名IsEnabled的,你可以在此改变。这就是所谓的每一行像getview。如果这个函数返回true onclicklistener才会触发。因此,尝试这样做,在你的customm适配器。

In the adapter there is a method name isEnabled which you can overide. This is called for each row like getview. The onclicklistener will only fire if this function returns true. So try doing that in your customm adapter.

@Override
public boolean isEnabled(int position) {
    if(YOUR CONDTITION){
        return false;
    }
    return true;
}

这篇关于Android的禁用列表视图项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆