0

카테고리 검색시 표시된 제품 중 price을 보여주는 앱의 TextView을 확인하려고합니다.필터 ID를 기반으로 한 텍스트 뷰어

저는 자동화를 위해 Robotium을 사용하고 있습니다. 목록보기의 아이들을 통해

  1. 트래버스 :

    ListView 
    --> (0)FrameLayout 
    --> (1)RelativeLayout 
         --> (0)ImageView 
         --> (1)RelativeLayout 
           -->(0)ImageView 
           -->(1)TextView //id - name 
           -->(2)TextView //id - price 
           -->(3)TextView //id - other 
    --> (2)RelativeLayout 
         --> (0)ImageView 
         --> (1)RelativeLayout 
           -->(0)ImageView 
           -->(1)TextView //id - name 
           -->(2)TextView //id - price 
           -->(3)TextView //id - other 
    
    --> (3)RelativeLayout 
         --> (0)ImageView 
         --> (1)RelativeLayout 
           -->(0)ImageView 
           -->(1)TextView //id - name 
           -->(2)TextView //id - price 
           -->(3)TextView //id - other 
    
    --> (4)RelativeLayout 
         --> (0)ImageView 
         --> (1)RelativeLayout 
           -->(0)ImageView 
           -->(1)TextView //id - name 
           -->(2)TextView //id - price 
           -->(3)TextView //id - other 
    
    --> (5)RelativeLayout 
         --> (0)ImageView 
         --> (1)RelativeLayout 
           -->(0)ImageView 
           -->(1)TextView //id - name 
           -->(2)TextView //id - price 
           -->(3)TextView //id - other 
    

    내가 가격을 얻는 두 가지 방법을 알아낼 수 :

    내가 현재보기를 얻을 계층 구조 (solo.getCurrentViews(ListView.class)) 같은 것이있다 색인을 통해 가격에 도달하십시오. 코드

    아래
    int index = 1; 
    ListView view = null; 
    
    List<ListView> productList = solo.getCurrentViews(ListView.class); 
    view = productList.get(0); 
    for (int i = 1; i < view.getChildCount(); i++) { 
        RelativeLayout relativeLayoutDetails = (RelativeLayout) view.getChildAt(index++); // get the first RelativeLayout 
    
        RelativeLayout productDetails = (RelativeLayout) relativeLayoutDetails.getChildAt(2); //get the inner child RelativeLayout 
        TextView productName = (TextView) productDetails.getChildAt(0); 
        System.out.println("********" + productDetails.getChildCount()); 
        TextView price = (TextView) productDetails.getChildAt(2); 
        System.out.println(productName.getText().toString() + "---"+ price.getText().toString()); 
    } 
    

같이이 코드의 문제는 나에게 price를 제공하지 않습니다 TextView price = (TextView) hotelDetails.getChildAt(2);하지만 나에게 other 텍스트 뷰를 (왜 몰라) 제공합니다. 또한 현재보기에서만 작동합니다. 전체 목록을 아래로 스크롤하여 각 제품마다 세부 정보를 얻을 수는 없습니다.

  1. 두 번째는 현재 뷰에 대한 모든 TextView의를 가져오고 price ID를 기반으로 그들을 필터링입니다. 아래처럼 :

    ListView l = (ListView) solo.getView (android.R.id.list); int viewShown = l.getChildCount();

     int total = l.getCount(); 
    
         int i; 
         int index=1; 
         if (hotelsShown != 0) { 
          for (i = 0; i < total/viewShown; i++) { 
    
    
            List<TextView> textViews = solo.getCurrentViews(TextView.class, l); //get all the text views 
            //filter for price 
            for(TextView priceView: textViews){ 
             if(priceView.id equals "price-id") 
               //get this TextView. 
            } 
    
           solo.scrollDown(); 
           solo.sleep(500); 
          } 
    

나는 내가 ID를 기반으로하는 뷰를 필터링 할 방법을 모르는되는이 방법에 직면하고 문제. 또한 스크롤하는 동안 현재보기에서 하나 또는 두 개의 제품을 건너 뛰고 수정할 수 없습니다.

누군가가 이와 관련하여 제안 할 수 있다면 좋을 것입니다.

+0

왜 각 ListView에 OnItemClickListener를 설정하지 않으시겠습니까? – Houcine

+0

어떻게 도움이 될까요? 내가 목록 항목을 클릭하면 새로운 계층 구조가 생깁니다. 죄송합니다 안드로이드 자동화에 새로운입니다. –

+0

코드를 추가하여 어댑터를 인스턴스화하고 목록보기로 설정하십시오. – Houcine

답변

2

목록의 색인 here에서 당신을 볼 수있는 나의 이전 대답 중 하나를 참조 할 것입니다.

이이 후에는 뷰의 모든 자식 요소 수를 새 기능을 결합 할 수 있습니다 :

private List<View> getAllChildren(View v) { 

    if (!(v instanceof ViewGroup)) { 
     ArrayList<View> viewArrayList = new ArrayList<View>(); 
     viewArrayList.add(v); 
     return viewArrayList; 
    } 

    ArrayList<View> result = new ArrayList<View>(); 

    ViewGroup viewGroup = (ViewGroup) v; 
    for (int i = 0; i < viewGroup.getChildCount(); i++) { 

     View child = viewGroup.getChildAt(i); 

     ArrayList<View> viewArrayList = new ArrayList<View>(); 
     viewArrayList.add(v); 
     viewArrayList.addAll(getAllChildren(child)); 

     result.addAll(viewArrayList); 
    } 
    return result; 
} 

다음 마지막으로 마지막 하나는 ID

으로보기 목록을 필터링하는 것입니다
public View(List<View> views, int idToMatch) { 
    for (View view : views) { 
     if (view.getId() == idToMatch) { 
      return view; 
     } 
    } 
    return null; 
} 

이 모든 것을 하나의 기능으로 조합하여 원하는대로 잘 할 수 있습니다. (R.id.price는 정수이므로 힌트를 얻으려는 아이디를 얻으려면 마지막 펑크 턴으로 넘어갑니다)

+0

Paul ..... 내 신입니다! –

관련 문제