2
當我選擇通過onClick在可點擊的TextView上調用函數時,如何獲取函數以瞭解哪個TextView調用了它?函數如何知道哪個可點擊的textView使用onClick調用它?
例如,當我有這個在我的MainActivity.java:
public void showHideData(View view)
{
//Log.v("showHideDataA: ", "Calling package null, local class name: " + this.getLocalClassName() + " request orientation: " + ("" + this.getRequestedOrientation()));
if (findViewById(R.id.letterContentTextViewArrayB).getVisibility() == View.VISIBLE)
{
findViewById(R.id.checkedB).setVisibility(View.GONE);
findViewById(R.id.notcheckedB).setVisibility(View.VISIBLE);
findViewById(R.id.letterContentTextViewArrayB).setVisibility(View.GONE);
}
else
{
findViewById(R.id.checkedB).setVisibility(View.VISIBLE);
findViewById(R.id.notcheckedB).setVisibility(View.GONE);
findViewById(R.id.letterContentTextViewArrayB).setVisibility(View.VISIBLE);
}
} // end of showHideData(0)
及以下TextViews:
<TextView
android:id="@+id/firstLetterTextViewArrayA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_a_label"
android:clickable="true"
android:onClick="showHideData"/>
<TextView
android:id="@+id/firstLetterTextViewArrayB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_b_label"
android:clickable="true"
android:onClick="showHideData" />
有沒有辦法讓showHideData(查看視圖)知道哪些TextView調用它?
謝謝
這是做你所需要的嗎? – codeMagic 2013-04-03 21:57:54
我遲到了,因爲我在丹麥! 我知道,有人會知道這件事。非常感謝,你確實爲我節省了很多煩人的代碼和很多難看的代碼! 我發現我應該使用案例R.id.firstLetterTextViewA而不是firstLetterTextViewA ... – 2013-04-04 05:57:14
沒問題。對不起這個錯字,我想我寫得很快。我編輯了我的帖子以反映這一點。謝謝! – codeMagic 2013-04-04 08:51:39