我有一个ExpandableListView
,其中包含RelativeLayout
个LinearLayout
个TextViews
个EditText
,其中包含 // 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();
}
});
,它会提取问题的答案并将该问题从1分配给-4(分别为坏,平庸,良好和世界级),最后为<?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>
用户留下评论他们为什么评分得分的问题。当用户单击分数框时,背景会更改颜色以突出显示所选分数,并将其他分数框颜色设置回其默认颜色,以显示它们不再被选中。下面是我的Java来展示它是如何工作的:
EditText
布局,以防相关:
onClick()
出于某种原因,当用户按下CustomListViewAdapter
并添加文本或点击时,按钮ExpandableListView
功能不再起作用(即,它们不再改变颜色)。
这是由焦点引起的吗? javacode onClick函数位于CREATE TABLE [DB]
(
ServerId INT,
[DBID] INT,
DBName varchar(255),
Createtime DATETIME,
LastCheckTime DATETIME
)
INSERT INTO [DB] VALUES
(1,1, 'DB1', '2010-09-10', '2013-09-01'),
(1,2, 'DB2', '2010-09-10', GETDATE()),
(1,3, 'DB3', '2010-09-12', GETDATE()),
(1,4, 'DB4', '2011-09-13', GETDATE()),
(1,5, 'DB5', '2011-09-10', GETDATE()),
(1,6, 'DB6', '2013-09-10', GETDATE()),
(1,7, 'DB7', '2014-09-10', GETDATE()),
(1,8, 'DB8', '2015-09-10', GETDATE()),
(1,9, 'DB9', '2016-09-10', GETDATE()),
(1,10, 'DB10', '2017-09-10', GETDATE());
--CTE holds all the years starting from the oldest DB
;WITH CTE
AS ( SELECT DATEPART(YEAR, ( SELECT MIN(CreateTime)
FROM [DB]
)) AS year
UNION ALL
SELECT year + 1
FROM CTE
WHERE year < DATEPART(YEAR, GETDATE())
)
SELECT year ,
COUNT(*) DBCount
FROM CTE
LEFT JOIN [DB] ON CTE.year BETWEEN DATEPART(YEAR, [DB].Createtime)
AND DATEPART(YEAR,
[DB].LastCheckTime + 1)
WHERE [DB].LastCheckTime > DATEADD(DAY, -1, GETDATE()) -- filter only live DBs
GROUP BY year;
中,以便能够为我所拥有的问题(大约200左右)提出相同的{{1}}。
答案 0 :(得分:1)
据我所知,问题在于View的重点。您可能需要使用OnFocusChangeListener,然后在屏幕处于触摸模式时检查焦点事件是否发生。
或者您可以尝试在每个onClick(视图视图)方法中添加这些行:
view.setFocusableInTouchMode(true);
view.requestFocus();
view.setFocusableInTouchMode(false);
这样,视图将获得焦点,并且在视图再次设置为setFocusableInTouchMode(false)之后,您可以在这些代码行之后在onClick()方法内部执行某些操作;