如何首先检查条件只在getview()中执行操作?

时间:2012-05-10 10:21:36

标签: android baseadapter

假设是那样的

  

图片字

但现在变得像那样

  

图像

     

图像和文字堆叠在一起开始时,当我滑动列表视图时,它只会变为

  

图片字

这是baseadapter中的getview

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.main_alllatestnewslist, parent,
                false);

    ImageView imageview = (ImageView) vi
            .findViewById(R.id.image_alllatestnewstitle);
    imageview.setVisibility(View.INVISIBLE);

    TextView titletext = (TextView) vi
            .findViewById(R.id.text_particularlatestnewstitle);

    if (!imagepath[position].toString().equals("no picture")) {

        titletext.setPadding(imageview.getWidth() + 5, 0, 0, 0);
        imageview.setVisibility(View.VISIBLE);
        imageLoader.DisplayImage(imagepath[position], imageview);
    } else {
        imageview.setVisibility(View.INVISIBLE);
        imageview.setImageDrawable(null);
        titletext.setPadding(0, 0, 0, 0);
    }

    titletext.setText(title[position].toString());
    return vi;
}

如何先检查然后设置仅填充显示?

1 个答案:

答案 0 :(得分:0)

if(position == 0){
   // enter code here
}
else{
   //enter code here
}