0
我的問題是未來。在這個main.xml示例中,我有一個有許多textview的RelativeLayout。單擊時在RelativeLayout中獲取textview的ID
main.xml中
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#000000"
android:id="@+id/RelativeLayout"
>
<TextView
android:id="@+id/tv00"
android:background="#ffffff"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="true"></TextView>
<TextView
android:id="@+id/tv01"
android:layout_width="wrap_content"
android:layout_below="@+id/tv00"
android:padding="5dp"
android:clickable="true"></TextView> ...
...</RelativeLayout>
我想在我的activity.java以訪問一個TextView我點擊的ID。怎麼做? 使用onClickListener,我可以在RelativeLayout上進行監聽,但是如何爲該佈局中的特定文本視圖執行此操作。與getid()有什麼關係?
activity.java
RelativeLayout rv =(RelativeLayout)findViewById(R.id.RelativeLayout);
rv.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
}
});
感謝所有幫助。
那麼我會使用盡可能多的setOnItemClickListener(),因爲有ListViews?我需要5列必須可點擊,然後,當我點擊一個文本視圖,它需要給我另一個活動,我將能夠修改它的內容(該文本視圖)。那可能嗎? – Beemo
是的,我認爲這應該起作用。 – user1101865
謝謝。這工作。現在我有其他問題:) – Beemo