我有一個ExpandableListView
他們的孩子是四LinearLayout
RelativeLayout
A S包含TextViews
這將拉動回答問題,並分配這個問題從1-4的得分(壞,平庸的,好的和世界一流的),最後還有一個EditText
讓用戶留下他們爲什麼對評分問題進行評分的評論。當用戶單擊樂譜框時,背景會更改顏色以突出顯示所選樂譜,並將其他樂譜框顏色設置恢復爲其默認顏色以顯示不再選擇它們。下面是我的Java來說明其工作原理:點擊EditText上導致按鈕的onClick()函數不行
// ChildView views
badScoreView = convertView.findViewById(R.id.qwedit_main_badView);
mediocreScoreView = convertView.findViewById(R.id.qwedit_main_mediocreView);
goodScoreView = convertView.findViewById(R.id.qwedit_main_goodView);
worldclassScoreView = convertView.findViewById(R.id.qwedit_main_wcView);
badScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_badTextView);
mediocreScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_mediumTextView);
goodScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_goodTextView);
worldClassScoreTextView = (TextView) convertView.findViewById(R.id.qwedit_main_worldclassTextView);
questionCommentEditText = (EditText) convertView.findViewById(R.id.qwedit_main_commentEditText);
// TODO: TextView score subcategory setters
badScoreView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 1;
badScoreView.setBackgroundColor(Color.parseColor("#eca9a7"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e"));
goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8"));
questionCommentEditText.clearFocus();
}
});
mediocreScoreView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 2;
badScoreView.setBackgroundColor(Color.parseColor("#d9534f"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f7d6a6"));
goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8"));
questionCommentEditText.clearFocus();
}
});
goodScoreView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 3;
badScoreView.setBackgroundColor(Color.parseColor("#d9534f"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e"));
goodScoreView.setBackgroundColor(Color.parseColor("#addbad"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#0275d8"));
questionCommentEditText.clearFocus();
}
});
worldclassScoreView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: add logic to change score
subCategoryScore = 4;
badScoreView.setBackgroundColor(Color.parseColor("#d9534f"));
mediocreScoreView.setBackgroundColor(Color.parseColor("#f0ad4e"));
goodScoreView.setBackgroundColor(Color.parseColor("#5cb85c"));
worldclassScoreView.setBackgroundColor(Color.parseColor("#80baeb"));
questionCommentEditText.clearFocus();
}
});
而且佈局,只是在相關情況:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/qwedit_elv_item_score_container"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/qwedit_main_badView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="@color/badScore">
<TextView
android:id="@+id/qwedit_main_badTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp"
android:text="Bad"/>
</LinearLayout>
<LinearLayout
android:id="@+id/qwedit_main_mediocreView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="@color/mediocreScore">
<TextView
android:id="@+id/qwedit_main_mediumTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp"
android:text="Mediocre"/>
</LinearLayout>
<LinearLayout
android:id="@+id/qwedit_main_goodView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="@color/goodScore">
<TextView
android:id="@+id/qwedit_main_goodTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp"
android:text="Good"/>
</LinearLayout>
<LinearLayout
android:id="@+id/qwedit_main_wcView"
android:layout_width="232.5dp"
android:layout_height="145.3dp"
android:background="@color/worldclassScore">
<TextView
android:id="@+id/qwedit_main_worldclassTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp"
android:text="World Class"/>
</LinearLayout>
</LinearLayout>
<EditText
android:id="@+id/qwedit_main_commentEditText"
android:layout_width="930dp"
android:layout_height="wrap_content"
android:layout_below="@+id/qwedit_elv_item_score_container"
android:cursorVisible="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="text"
android:hint="Comments"/>
</RelativeLayout>
出於某種原因,當用戶按下EditText
,要麼添加文字或點擊它,按鈕onClick()
功能不再起作用(即它們不再改變顏色)。
這是由於某些焦點? javacode onClick函數的格式爲CustomListViewAdapter
,以便能夠爲相同的ExpandableListView
增加相同數量的問題(約200個左右)。
刪除此行:android:focusableInTouchMode =「true」 – amacf
嗯,這似乎沒有它。問題繼續存在,無論那條線是否存在或不存在 – Tadhg