緣起
简小郎
findViewsWithText的使用
菩薩慈悲,末學在Visual Studio 2019 以 C# 來照菩薩您所示的實作findviewsWithText方法,卻沒有作用。還不如末學用 for 迴圈和 ChildCount 來實作。
照您所示,加了contentDescription 属性,也無法比對出來,傳個空的ArrayList給它作引數,它也儲存不到比對的結果來輸出,而這個ArrayList壓根兒沒有什麼丁點的動靜。末學逐步偵錯則發現 findviewsWithText 方法根本只會迭代(iterate)ArrayList,卻不去做調用findviewsWithText的物件(object)內View的比對。
末學在Visual Studio中讀其定義,也看不到菩薩您這裡所示的View和 View裡的findViewsWithText實作,只有以下這樣:
//
// 摘要:
// To be added.
//
// 參數:
// outViews:
// To be added.
//
// searched:
// To be added.
//
// flags:
// To be added.
//
// 備註:
// Portions of this page are modifications based on work created and shared by the
// Android Open Source Project and used according to terms described in the Creative
// Commons 2.5 Attribution License.
[Register("findViewsWithText", "(Ljava/util/ArrayList;Ljava/lang/CharSequence;I)V", "GetFindViewsWithText_Ljava_util_ArrayList_Ljava_lang_CharSequence_IHandler")]
public virtual void FindViewsWithText(IList<View>? outViews, ICharSequence? searched, [GeneratedEnum] FindViewsWith flags);
//
// 摘要:
// To be added.
//
// 參數:
// outViews:
// To be added.
//
// searched:
// To be added.
//
// flags:
// To be added.
//
// 備註:
// Portions of this page are modifications based on work created and shared by the
// Android Open Source Project and used according to terms described in the Creative
// Commons 2.5 Attribution License.
public void FindViewsWithText(IList<View>? outViews, string? searched, [GeneratedEnum] FindViewsWith flags);
不知問題出在哪裡,是C#不行嗎?沒有像菩薩這裡這樣的實作嗎?菩薩您這應該是 Java吧?
末學程式碼詳下:
https://blog.youkuaiyun.com/oscarsun72/article/details/108227131
感恩感恩 南無阿彌陀佛
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.Animation;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
//using Java.Lang;
//using Java.Lang.Reflect;
using Java.Util;
namespace GuessGameAndroidPractise {
public class MyViewClass : IList<View> {
Java.Util.ArrayList _arrView = new Java.Util.ArrayList ();
View IList<View>.this [int index] {
get => (View) _arrView.Get (index); set => _arrView.Set (index, (View) value); }
internal MyViewClass (Java.Util.ArrayList arrView) {
_arrView = arrView;
}
int ICollecti