适配器getView不返回我想要的行

时间:2014-01-14 18:46:19

标签: android adapter

我在getView()中有一些“if”语句,我希望返回if块中的行,但是虽然条件为真,但我没有得到行,但是我得到了行函数的return语句(最后一行)。 我一直收到错误的行!!(if语句之外的行)  代码可以解释我的英语不能做的事情:

...你可以帮我解决错误!!

      public View getView(int position, View convertView, ViewGroup parent) {
                Log.e("SOMAA","Type: "+ thisItems.get(position).type+" ");
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
                View row = inflater.inflate(R.layout.msgfromme, parent, false); ;

                if(thisItems.get(position).type==MessageType.TextMessage)
                 {
                     Log.e("SOMAA","in if type text");
                if (thisItems.get(position).mFrom.equals("Me: ")) {
                    Log.e("SOMAA","Partener = Me ");
                    row = inflater.inflate(R.layout.msgfromme, parent, false);
                    ImageView STATUS = (ImageView) row.findViewById(R.id.sent_indecator);
                    STATUS.setImageResource(thisItems.get(position).sent_icon);
                } else
                {
                    row = inflater.inflate(R.layout.msgtome, parent, false);
                    thisItems.get(position).mFrom="Stranger";
                    Log.e("SOMAA","Partener = Stranger ");
                }
                //Get::
                ImageView partnerImg = (ImageView) row.findViewById(R.id.myimage);
                TextView partner = (TextView) row.findViewById(R.id.frommepartner);
                TextView msg = (TextView) row.findViewById(R.id.msgtohim);
                TextView timespam = (TextView) row.findViewById(R.id.timefromme);
                //Set::
                partnerImg.setImageResource((thisItems.get(position)).mImage);
                partner.setText(thisItems.get(position).mFrom);
                timespam.setText(thisItems.get(position).mTimeStamp);
                msg.setText(thisItems.get(position).mMsgbdy, TextView.BufferType.SPANNABLE);
                     return row;// I want this row <<<<<----
                 }
    //---------------------------------------------------------------------------------------------------------
               else if (thisItems.get(position).type==MessageType.urlToParter)
                 {
                    Log.e("SOMAA","In  else if (thisItems.get(position).type==MessageType.urlToParter) : " + (thisItems.get(position).type));
                     Log.e("SOMAA",thisItems.get(position).url);
                     if (thisItems.get(position).mFrom.equals("Me: ")) {
                         row = inflater.inflate(R.layout.image_row_from_me, parent, false);
                 } else{
                         row = inflater.inflate(R.layout.image_row_to_me, parent, false);
                         thisItems.get(position).mFrom="Stranger";
                     }
                     //Get::
                     ImageView imageShow = (ImageView) row.findViewById(R.id.imgsrc);
                     TextView partner = (TextView) row.findViewById(R.id.partner_send_image);
                     TextView timespam = (TextView) row.findViewById(R.id.timeimg);
                     //Set::
                     Log.d("SOMAA","Reading File");
                     thisItems.get(position).url=thisItems.get(position).url.replace("\\","/");
                     File imgFile = new  File(thisItems.get(position).url);
                     Log.d("SOMAA","is exist file"+imgFile.exists());
                     if(imgFile.exists()){

                    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                    imageShow.setImageBitmap(myBitmap);
                     partner.setText(thisItems.get(position).mFrom);
                     timespam.setText(thisItems.get(position).mTimeStamp);

                      }

                     return row;  // OR this row <<<<<----
}
                Log.e("SOMAA","OOOPS, Not our row!!");
                return row;//But <<<<< I Always get this row
            }
**Update:**
Logcat|:

    01-14 15:37:26.929    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:37:33.129    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:33.319    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:37:33.878    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:33.929    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:37:45.889    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:45.928    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:37:49.520    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:49.558    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:37:51.619    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:51.679    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:51.729    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:37:52.309    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:52.339    1644-1644/? E/SOMAA﹕ Type: 0
    01-14 15:37:52.388    1644-1644/? E/SOMAA﹕ Type: 100
    01-14 15:48:14.229    1693-1709/? E/SOMAA﹕ in handletext message
    01-14 15:48:14.264    1693-1709/? E/SOMAA﹕ msg body: 65+5+65
    01-14 15:48:16.139    1693-1693/? E/SOMAA﹕ Type: 100
    01-14 15:48:16.189    1693-1693/? E/SOMAA﹕ in if type text
    01-14 15:48:16.219    1693-1693/? E/SOMAA﹕ Partener = Stranger
    01-14 15:48:34.329    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:48:34.439    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:48:34.489    1693-1693/? E/SOMAA﹕ Type: 100
    01-14 15:48:34.530    1693-1693/? E/SOMAA﹕ in if type text
    01-14 15:48:34.629    1693-1693/? E/SOMAA﹕ Partener = Stranger
    01-14 15:49:20.178    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:49:20.248    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:49:20.270    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:49:20.288    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:49:20.308    1693-1693/? E/SOMAA﹕ Type: 100
    01-14 15:49:20.338    1693-1693/? E/SOMAA﹕ in if type text
    01-14 15:49:20.368    1693-1693/? E/SOMAA﹕ Partener = Stranger
    01-14 15:49:20.918    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:49:20.948    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:49:20.968    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:49:20.988    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:49:21.008    1693-1693/? E/SOMAA﹕ Type: 100
    01-14 15:49:21.038    1693-1693/? E/SOMAA﹕ in if type text
    01-14 15:49:21.058    1693-1693/? E/SOMAA﹕ Partener = Stranger
    01-14 15:51:16.128    1693-1693/? E/SOMAA﹕ imageeeee image C:\wamp\www\RandomSendServer\images\1389714677174.gif
    01-14 15:51:18.049    1693-1693/? E/SOMAA﹕ in handletext message
    01-14 15:51:18.059    1693-1693/? E/SOMAA﹕ msg body:
    01-14 15:51:18.338    1693-1693/? E/SOMAA﹕ Type: 100
    01-14 15:51:18.379    1693-1693/? E/SOMAA﹕ in if type text
    01-14 15:51:18.419    1693-1693/? E/SOMAA﹕ Partener = Stranger
    01-14 15:51:18.439    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:51:18.468    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:51:18.488    1693-1693/? E/SOMAA﹕ Type: 0
    01-14 15:51:18.529    1693-1693/? E/SOMAA﹕ OOOPS, Not our row!!
    01-14 15:51:18.559    1693-1693/? E/SOMAA﹕ Type: 100
    01-14 15:51:18.579    1693-1693/? E/SOMAA﹕ in if type text
    01-14 15:51:18.619    1693-1693/? E/SOMAA﹕ Partener = Stranger

100 =的TextMessage

1 个答案:

答案 0 :(得分:0)

如上所述,目前尚不清楚真正的问题是什么,但不要忘记在线程中调用getView()方法!所以它并不是那么具有说服力的,也许这就是为什么你得到的结果是你没想到的(基本上是“错误的”顺序)。