我有一个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