如何模拟单击Listview项目?

时间:2017-05-15 12:48:16

标签: android listview nullreferenceexception

我尝试通过 OnResume

来模拟点击列表视图的第一项
public Task<Metadata> GetMetadataAsync(
    string path,
    bool includeMediaInfo = false,
    bool includeDeleted = false,
    bool includeHasExplicitSharedMembers = false,
    CancellationToken ct = null /*This is would be optional cancellation token. But this parameter doesn't exist in API*/
);

但是我在空对象引用 上得到错误

listView.getAdapter().getView(0, null, null).performClick();

1 个答案:

答案 0 :(得分:0)

试试这个。

final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
      @Override
      public void run() {
        listView.getAdapter().getView(0, null, null).performClick();
      }
    }, 1500);