2012-10-12 42 views
0

我怎麼可以這樣調用後顯示在GET鑑於TextView文本TextView中如何顯示文本

ListAdapter adapter = new MyCustomAdapter ( 
         ManageSection.this, studentList, 
         R.layout.list_student, new String[] { TAG_StudentID, 
           TAG_StudentNo,TAG_FullName}, 
         new int[] { R.id.StudentID, R.id.StudentNo,R.id.FullName}); 
       setListAdapter(adapter); 

和類MyCustomAdapter有一個get的看法,我將顯示文本

 holder.FullName= (TextView) convertView.findViewById(R.id.FullName); 
     holder.FullName.setText(); 
     holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo); 
     holder.StudentNo.setText(); 

所以在設置文本我應該寫什麼因爲我做

no=student.get(holder.position).get(TAG_StudentNo); 
      name =student.get(holder.position).get(TAG_FullName); 

並採取不,名稱,但tex t在整個列表中重複

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


    final ViewHolder holder; 
     if(convertView==null) 
     { 
      LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = mInflater.inflate(resource, parent, false); 
      holder = new ViewHolder(); 
      no=student.get(holder.position).get(TAG_StudentNo); 
      name =student.get(holder.position).get(TAG_FullName); 
      holder.StudentID= (TextView) convertView.findViewById(R.id.StudentID); 
      holder.FullName= (TextView) convertView.findViewById(R.id.FullName); 
      holder.FullName.setText(); 
      holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo); 
      holder.StudentNo.setText(); 
      holder.DeleteStudent = (ImageView) convertView.findViewById(R.id.DeleteStudent); 
      holder.AlertIcon = (ImageView) convertView.findViewById(R.id.Alert); 

     // add a listener for phone call 
      holder.DeleteStudent.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 

       id = student.get(holder.position).get(TAG_StudentID); 
       Toast.makeText(getContext(),id,Toast.LENGTH_LONG).show(); 


       } 

      }); 


      holder.AlertIcon.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 

       // String email = MyCustomAdapter.listMap.get(holder.position).get("email"); 
        // ActivityHelper.startActivity(ActivityManager.EMAIL, email); 
       } 

      }); 

      convertView.setTag(holder); 

     } 
     else 
     { 
      holder = (ViewHolder) convertView.getTag(); 
     } 
     holder.position = position; 
     return convertView; 
    } 

    private static class ViewHolder 
    { 
     ImageView DeleteStudent; 

     ImageView AlertIcon; 

     TextView StudentID, StudentNo ,FullName; 

     int position; 
    } 


} 

任何人都可以告訴我這是什麼問題嗎?

回答

1

試試看看這個代碼。

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


final ViewHolder holder; 
    if(convertView==null) 
    { 
     LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = mInflater.inflate(resource, parent, false); 
     holder = new ViewHolder(); 
     convertView.setTag(holder); 

    } 
    else 
    { 
     holder = (ViewHolder) convertView.getTag(); 
    } 
    holder.position = position; 
    no=student.get(holder.position).get(TAG_StudentNo); 
    name =student.get(holder.position).get(TAG_FullName); 
    holder.StudentID= (TextView) convertView.findViewById(R.id.StudentID); 
    holder.FullName= (TextView) convertView.findViewById(R.id.FullName); 
    holder.FullName.setText(); 
    holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo); 
    holder.StudentNo.setText(); 
    holder.DeleteStudent = (ImageView) convertView.findViewById(R.id.DeleteStudent); 
     holder.AlertIcon = (ImageView) convertView.findViewById(R.id.Alert); 

    // add a listener for phone call 
     holder.DeleteStudent.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 

      id = student.get(holder.position).get(TAG_StudentID); 
      Toast.makeText(getContext(),id,Toast.LENGTH_LONG).show(); 


      } 

     }); 


     holder.AlertIcon.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 

      // String email = MyCustomAdapter.listMap.get(holder.position).get("email"); 
       // ActivityHelper.startActivity(ActivityManager.EMAIL, email); 
      } 

     }); 



    return convertView; 

}

private static class ViewHolder 
{ 
    ImageView DeleteStudent; 

    ImageView AlertIcon; 

    TextView StudentID, StudentNo ,FullName; 

    int position; 
} 

}

什麼你做的是剛剛設置的數據只有當convertView爲空,如果你不只是將一些支架手術後的看法。您需要在每種情況下在textView中設置文本等。如果您需要更多解釋,請詢問。

+0

非常感謝您的評論 – sara

1

其簡單的哥們你剛剛已經把這一行,而不是空白setText()

​​

,你只需要通過no和「名variable to的setText()`方法。