2012-10-12 3 views
0

나는이 호출 후 GET보기에서 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가 null 인 경우에만 데이터 만 설정하고 그렇지 않으면 당신은 그냥 홀더 수술 후보기를 반환하고 있었다. 모든 경우 TextView에 Text 등을 설정해야합니다. 더 자세한 설명이 필요하면 질문하십시오.

+0

의견을 보내 주셔서 감사합니다. – sara

1

단순한 친구 U는 그냥 no와 '이름 variable to의 setText()`방법을 통과해야

no=student.get(holder.position).get(TAG_StudentNo);// the roll_number string 
name =student.get(holder.position).get(TAG_FullName);//full name string 
holder.StudentID= (TextView) convertView.findViewById(R.id.StudentID); 
holder.FullName= (TextView) convertView.findViewById(R.id.FullName); 
holder.FullName.setText(name);//pass fullname 
holder.StudentNo=(TextView) convertView.findViewById(R.id.StudentNo); 
holder.StudentNo.setText(no);//pass roll no. 

setText() 대신이 줄을 추가해야합니다.