我想自动化一个场景,比如点击一个位于ListView中位置2的按钮。 PFB代码会自动单击ListView中索引1处的按钮
TextView a = (TextView)solo.getView(R.id.dialog);
solo.clickOnView(a);
答案 0 :(得分:0)
U具有该按钮的特定ID。为该按钮设置setTag()
标签,然后设置点击事件::喜欢
getView((int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = context.getLayoutInflater();
// use inflater and do all those normal things..
}
view.setTag(position);
myButton.setTag(view.getTag());
myButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getContext()," Slot Button clicked " + v.getTag(),Toast.LENGTH_SHORT).show();
}
});
答案 1 :(得分:0)
为什么不在ListViews项目中使用 performClick()方法,如下所示:
((Button)((View) listView.get(1)).findViewById(R.id.mybutton)).performClick();
如果您只想制作itemClick,则应使用 ListView 的 onItemCkick()