2015-09-20 20 views
1

我一直在嘗試在屏幕或佈局中破解所有類型標籤元素的foreach,但沒有運氣! 我的目標是翻譯所有screen1.labels.text,翻譯列表中有對(label.text,translation)列表。 這是可能的應用發明者?對於佈局或屏幕中的每個元素

+0

我剛剛發現這個解決方案,但我想做的事情,而不必在分離的列表中添加所有元素。 https://amerkashi.wordpress.com/2014/08/21/anycomponent/ – meYnot

回答

3

你有沒有想過獲取子視圖的數組列表並迭代思考它們。以下將適用於屏幕的直接子女。如果你需要子視圖以及你可以使用遞歸

RelativeLayout layout = (RelativeLayout)findViewById(R.id.your_screen_to_search); 
for (int i = 0; i < layout.getChildCount(); i++) 
{ 
    View child = layout.getChildAt(i); 
    if(child instanceOf TextView) 
    { 
     txtView = (TextView)child; 
     if(txtView.getText().length!=0) 
     { 
      yourTranslateFunction(txtView.getText()); 
     } 
    } 
} 
+0

如果有效,你會接受答案嗎? –

+0

我期待App-Inventor的回答! – meYnot

+0

哦,對不起,我無法幫助 –

相關問題