Reference Basic GirdView Program to here.
Add OnClikcListener() include GridView. It is include position information. I create other
OnClickListener Class.
class OnClickListenerDetectPosition implements OnClickListener { private int mPosition = 0; public OnClickListenerDetectPosition(int position ) { mPosition = position; } @Override public void onClick(View v) { Log.d("GridViewActivity", "onClick = " + mPosition); } }register OnClickListner by it.
OnClickListener onclikclistener = new OnClickListenerDetectPosition(position); imageView.setOnClickListener(onclikclistener);Second, Tester. It is extends ActivityInstrumentationTestCase2. set position. must be UIThread
mActivity.runOnUiThread(new Runnable() { public void run() { Log.d("GridViewActivity", "setSelection 2"); gridview.setSelection(2); } }); mInstrumentation.waitForIdleSync();get selected view and click view.
mActivity.runOnUiThread(new Runnable() { public void run() { Log.d("GridViewActivity", "getSelectedItemPosition = " + gridview.getSelectedItemPosition ()); Log.d("GridViewActivity", "getSelectedView"); ImageView imageview = (ImageView)gridview.getSelectedView(); Log.d("GridViewActivity", "performClick"); imageview.performClick(); } });Check Logcat.
setSelection 2 getSelectedItemPosition = 2 onClick = 2It is OK.
Test target source code is here.
Tester source code is here.
0 件のコメント:
コメントを投稿