Android ListView: getTag() returns null

Posted by TianDong on Stack Overflow See other posts from Stack Overflow or by TianDong
Published on 2010-06-14T20:56:46Z Indexed on 2010/06/14 21:02 UTC
Read the original article Hit count: 1166

Filed under:
|
|

Hallo all,

I have a ListView which contains a Button in each line. The following code is part of the getView() Method

public View getView(final int position, View convertView, ViewGroup parent) {
        View row = convertView;
        TextView tv;
        Button saveA_button;
        EditText edittext;
        FITB_ViewWrapper wrapper;

  if (row == null) {
       LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       if (ChooseMode_Act.modeInfo.equalsIgnoreCase("Training")) { 
             row = li.inflate(R.layout.exercise_for_training_fitb,parent, false);
       }else {
              row = li.inflate(R.layout.exercise_for_exam_fitb,parent, false);
       }
       wrapper=new FITB_ViewWrapper(row);
       row.setTag(wrapper);
       if (ChooseMode_Act.modeInfo.equalsIgnoreCase("Exam")) {
           saveA_button=wrapper.getSaveAnswer_Button();
           OnClickListener l=new OnClickListener() {

               @Override
               public void onClick(View v) {
                     Integer mp=(Integer)v.getTag();
                     Log.i("mp","my Position is: "+mp);
               }
          };
          saveA_button.setOnClickListener(l);
       }
   }else {
           wrapper=(FITB_ViewWrapper) row.getTag();
 }

For my App i need to known to which item the Button belongs to, so i try to detect it. The code

Log.i("mp","my Position is: "+mp);

puts out a message: mp myPosition is: null

I can't understand, why do i get a "null" but not an Integer? How can i find out the Position of an Item in a ListView?

Thanks a lot.

© Stack Overflow or respective owner

Related posts about android

Related posts about listview