2012-07-01 4 views
1

내가 ArrayAdapter와 있습니다ListView를 선택 행

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
     View v = convertView; 
     if (v == null) { 
      LayoutInflater vi = (LayoutInflater)LayoutInflater.from(context); 
      v = vi.inflate(R.layout.consumerlist_row, null); 
     } 

     SharedClass.GenericItem item = SharedClass.consumerList.get(position); 

     if (item != null) { 

      final GenericItem fitem = item; 
      v.setOnClickListener(new OnClickListener() { 

       public void onClick(View v) { 

        int id = ID = ((ExtEditText)v.findViewById(R.id.dayreadout_entry)).getIdentifyingNumber(); 
        if(prevID!=ID){ 
         if(!((ExtEditText)v.findViewById(R.id.dayreadout_entry)).isSelected() 
          &&!((ExtEditText)v.findViewById(R.id.nightreadout_entry)).isSelected()){ 


          if(fitem.GetIdAddress()==ID){ 
//Set unique identificator of 
           ((ExtEditText)v.findViewById(R.id.dayreadout_entry)).setChosen(true); 
           TransitionDrawable drawable = (TransitionDrawable) v.getBackground();                 
           drawable.startTransition(animSpeed); 
          } 

          if(prevID!=-1){ 
           CloseEditMode();          
           LeaveRow(prevRow, prevID);          
          } 
          prevRow = v; 
          prevID=ID;        
         } 
        } 
       } 
      }); 
SetColorToRow(v, item);  
     return v; 
} 

LeaveRow :

private void LeaveRow(View row, int id){  
    int ids = ((ExtEditText)row.findViewById(R.id.dayreadout_entry)).getIdentifyingNumber(); 
    if(id==ids){ 
    SharedClass.GenericItem item = GetItemByID(id); 
    ((ExtEditText)row.findViewById(R.id.dayreadout_entry)).setChosen(false);     

      TransitionDrawable tDrawable = (TransitionDrawable)row.getBackground();        
      tDrawable.reverseTransition(animSpeed); 
} 

} 

SetColorToRow :

private void SetColorToRow(View v, GenericItem item){ 

    boolean ids = ((ExtEditText)v.findViewById(R.id.dayreadout_entry)).isChosen(); 

    String day = String.valueOf(item.GetDay()); 
    String night = String.valueOf(item.GetNight()); 
    String skipped = String.valueOf(item.GetSkipped()); 

    if(day.equals("-9999999")&&night.equals("-9999999")&&!skipped.equals("0")){ 
     if(ids){ 
      TransitionDrawable td = (TransitionDrawable) v.getBackground(); 
      td.startTransition(animSpeed); 
     } 
     else 
      v.setBackgroundResource(R.drawable.listviewitem_yellow_blue);   
    } 
    else if(day.equals("-9999999")&&night.equals("-9999999")&&skipped.equals("0")){ 
     if(ids){ 
      TransitionDrawable td = (TransitionDrawable) v.getBackground(); 
      td.startTransition(animSpeed); 
     } 
     else 
      v.setBackgroundResource(R.drawable.listviewitem_white_blue);       
    } 
    else { 
     if(ids) { 
      TransitionDrawable td = (TransitionDrawable) v.getBackground(); 
      td.startTransition(animSpeed); 
     } 
     else 
      v.setBackgroundResource(R.drawable.listviewitem_green_blue);       
    } 

} 

내가 행을 선택하면 문제가 (행이 청색을 변) 및 목록을 아래로 이동 (행이 사라지면) 다른 행을 선택합니다. 행의 상태를 복사하여 아래 목록에 넣은 것 같습니다.

--------REAL SELECTED ROW-------- 

--------------------------------- 
|        | 
|        | 
|        | 
|   LIST VIEW   | 
|        | 
|        | 
|        | 
|-----WRONG SELECTED ROW--------| 
|        | 
--------------------------------- 

내가 뭘 잘못하고 있니? 도와주세요.

답변

0

내가이 일하기 어댑터에 필드를 추가 발견했습니다

private int selectedIndex; 
    public void setSelectedIndex(int index){ 
      this.selectedIndex = index; 
    } 
    //Your activity or controller can access this index at any time. 
    public int getSelectedIndex(){return selectedIndex;} 

을 공개보기의 getView (INT 위치보기 convertView, 뷰 그룹의 부모)에서에 그런

if(selectedIndex == position){ 
      convertView.setBackground(R.id.some_resource_selectable); 
    }else{ 
    //set background null 
      convertView.setBackground(null); 
    } 

항목을 클릭 리스너에 내 목록보기는

 onItemClick (AdapterView<?> parent, View view, int position, long id){ 
      adapter.setSelectedIndex(position); 
      adapter.notifyDataSetChanged(); 
     } 

희망이

하는 데 도움이