Android禁用列表视图项

所以基本上我需要一些帮助或一些我有问题的建议。我从数据库填充我的列表视图,如果项目的位置id与数据库中另一个表的id相同,我需要检查我创建我的列表视图。如果是,您可以点击该项目,如果不是我想要它禁用它,但所有的信息,我发现如何做到这一点我不能真正了解如何做到这一点。

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;
    }
}

任何想法或建议如何做到这一点?

在适配器中有一个名为isEnabled的方法可以覆盖。这样就像getview那样调用每一行。如果此函数返回true,onclicklistener将仅触发。所以请尝试在您的customm适配器。

@Override
public boolean isEnabled(int position) {
    if(YOUR CONDTITION){
        return false;
    }
    return true;
}
http://stackoverflow.com/questions/7778906/android-disable-listview-items

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:Android禁用列表视图项