列表视图中的ImageView问题

时间:2014-08-20 17:24:40

标签: android

我正在使用listview。 imageView2即img2最初设置为不可见,并在检查coloumn的值后可见。如果它是“是”则imageView2变为不可见。我已经检查了我的数据库仍然listview显示图像,即使该编码不满足。哪里可能是我的错?我也尝试了ViewHolder ......但是工作很好!

public class ArrayAdapter1 extends BaseAdapter
{

ImageView iv,im1,im2,img3,img4,img5;
int items=0;
int time;
int hr=00; int min=00;
int cmin;
ArrayList<String> apps;
ArrayList<Integer> timer;
private LayoutInflater inflater;
private List<ResolveInfo> mApps;
Context context;
DBHelper helper;
MainActivity ma;
public ArrayAdapter1(Context context, List<ResolveInfo> mApps) 
{
    this.inflater = LayoutInflater.from(context);
    this.mApps = mApps;
    this.context=context;
    apps=new ArrayList<String>();
    timer=new ArrayList<Integer>();
    helper=new DBHelper(context);
    ma=new MainActivity();
}



public View getView(final int position, View convertView, ViewGroup parent) 
{

    final TextView tv1;
    TextView tv2,tv3;
    ImageView img1,img2;
    final ImageButton ib;

    View view=convertView;
    if (view == null) 
    {
        convertView = inflater.inflate(R.layout.row,parent, false);

        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.row, null,false);
    } 

    tv1= (TextView)convertView.findViewById(R.id.textView1);
    tv2= (TextView)convertView.findViewById(R.id.textView2);
    tv3= (TextView)convertView.findViewById(R.id.textView3);
    //tv2.setTextColor(Color.GREEN);
    img1= (ImageView)convertView.findViewById(R.id.imageView1);
    img2=  (ImageView)convertView.findViewById(R.id.imageView2);
    img3=  (ImageView)convertView.findViewById(R.id.imageView3);
    img4=  (ImageView)convertView.findViewById(R.id.imageView4);
    img5=  (ImageView)convertView.findViewById(R.id.imageView5);


    ResolveInfo info = this.mApps.get(position);
    String app=info.loadLabel(context.getPackageManager()).toString();
    tv1.setText(app);
    img1.setImageDrawable(info.activityInfo.loadIcon(context.getPackageManager()));
    //tv2.setText(helper.getState(app));
    tv3.setText(helper.getCurr_time(app));
    tv2.setText(helper.getLimit(app)); 

    if(helper.getNote(app)!=null)
    {
    String note=helper.getNote(app);
    if(note.equals("yes")){img2.setVisibility(View.VISIBLE);} else  {img2.setVisibility(View.INVISIBLE);}
    }

    String type = null;
    if(helper.getType(app)!=null)
    {
    type=helper.getType(app);
    if(type.equals("Day Lock")) {img4.setVisibility(View.VISIBLE);}   else  {img4.setVisibility(View.INVISIBLE);}
    if(type.equals("Child Lock")) {img3.setVisibility(View.VISIBLE);}   else  {img3.setVisibility(View.INVISIBLE);}
    }



    if(helper.getState(app)!=null)
    {
    String state=helper.getState(app);
    if(state.equals("BLOCKED")) {img5.setVisibility(View.VISIBLE); img4.setVisibility(View.INVISIBLE);  img3.setVisibility(View.INVISIBLE);}   
    else  {img5.setVisibility(View.INVISIBLE);}
    }

    return convertView;

}
public final int getCount() {
    return mApps.size();
}

public final Object getItem(int position) {
    return mApps.get(position);
}

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

这是我的MainAcitivity中的块,我将值设置为null以隐藏图像。

listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub
            TextView tv1=(TextView)arg1.findViewById(R.id.textView1);
            String name=tv1.getText().toString();

            // for notified app ! 
            ImageView img=(ImageView)arg1.findViewById(R.id.imageView2);
            img.setVisibility(View.INVISIBLE);

            if(helper.getNote(name)!=null)
            {  helper.setNote(name,"");  }  // for notified app ! 

            AlertDialog dialog= (AlertDialog) oncreateDialog(name);//,arg3);//<<pass selected index
            dialog.show(); 

            return true;
        }
    });

0 个答案:

没有答案