是否可以在单击时更改列表视图项目的颜色,并且在再次单击之前,它将一直是该颜色?我使用适配器从Firebase获取数据。
答案 0 :(得分:0)
是的,可以在单击时更改列表视图中某个项目的颜色,直到再次单击它为止,它将一直是该颜色。 只需在您的适配器中写一个项目,然后根据您的条件更改颜色即可。
// Darbuotoju valdymas prasideda //
public void darbuotojuVald() {
System.out.println("---- Darbuotoju valdymas ----");
System.out.println("[1] Prideti nauja darbuotoja");
System.out.println("[2] Pasalinti darbuotoja");
System.out.println("[3] Atnaujinti darbuotoja");
System.out.println("[4] Pamatyti darbuotoju sarasa");
System.out.println("[5] Gauti informacija apie pasirinkta darbuotoja");
Scanner SI = new Scanner(System.in);
int vartotojoIvestis = Integer.parseInt(SI.nextLine());
if (vartotojoIvestis == 1) {
System.out.println("---- Prideti nauja darbuotoja ----");
System.out.println("[1] Programuotoja");
System.out.println("[2] kita");
int vartotojoIvestis2 = Integer.parseInt(SI.nextLine());
if (vartotojoIvestis2 == 1) {
pridetiDarbuotojaProgramuotoja();
} else {
System.out.println("In progress....");
}
} else if (vartotojoIvestis == 4) {
bendrasDarbuotojuSarasas();
}
}
// Programuotojo pridejimas prasideda //
private void pridetiDarbuotojaProgramuotoja() {
System.out.println("---- Pridedamas naujas programuotojas ----");
System.out.println("Iveskite:");
System.out.println("Varda, pavarde, amziu, patirti, programavimo kalba");
Scanner SI = new Scanner(System.in);
String[] iveda = SI.nextLine().split(" ");
programuotojas.add(new Programuotojas(iveda[0], iveda[1], Integer.parseInt(iveda[2]), Integer.parseInt(iveda[3]), iveda[4]));
System.out.println("---- Sekmingai pridetas naujas darbuotojas ----");
System.out.println("Vardas: " + iveda[0]
+ ",pavarde: " + iveda[1]
+ ",amzius: " + iveda[2]
+ ",patirtis: " + iveda[3]
+ ",programavimo kalba: " + iveda[4]);
darbuotojuSarasas.clear();
darbuotojuSarasas.addAll(programuotojas);
darbuotojuVald();
}
private void bendrasDarbuotojuSarasas() {
System.out.println("---- Visas darbuotoju sarasas ----");
for(int i = 0; i < darbuotojuSarasas.size(); i++) {
System.out.println("ID " + i + " " + darbuotojuSarasas.get(i));
}
darbuotojuVald();
}
如果您需要另一个示例,请告诉我。 #KeepCoding
答案 1 :(得分:0)
如果您只想更改一次颜色:
[error] Driver stacktrace:
[error] at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1599)
[error] at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1587)
[error] at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1586)
[error] at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
[error] at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
[error] at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1586)
[error] at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:831)
[error] at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:831)
[error] at scala.Option.foreach(Option.scala:257)
[error] at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:831)
[error] at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1820)
[error] at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1769)
[error] at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1758)
[error] at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
[error] at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:642)
[error] at org.apache.spark.SparkContext.runJob(SparkContext.scala:2027)
[error] at org.apache.spark.SparkContext.runJob(SparkContext.scala:2048)
[error] at org.apache.spark.SparkContext.runJob(SparkContext.scala:2067)
[error] at org.apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:363)
[error] at org.apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)
[error] at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$collectFromPlan(Dataset.scala:3272)
[error] at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2484)
[error] at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2484)
[error] at org.apache.spark.sql.Dataset$$anonfun$52.apply(Dataset.scala:3253)
[error] at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:77)
[error] at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3252)
[error] at org.apache.spark.sql.Dataset.head(Dataset.scala:2484)
[error] at org.apache.spark.sql.Dataset.take(Dataset.scala:2698)
[error] at org.apache.spark.sql.Dataset.showString(Dataset.scala:254)
[error] at org.apache.spark.sql.Dataset.show(Dataset.scala:723)
[error] at org.apache.spark.sql.Dataset.show(Dataset.scala:682)
[error] at org.apache.spark.sql.Dataset.show(Dataset.scala:691)
[error] at Main$.main(Main.scala:101)
[error] at Main.main(Main.scala)
[error] Caused by: scala.MatchError: [59,WrappedArray(-0.17827, 0.41787, 0.043321, -0.2759, 0.71027, -0.17696, 0.1804, -0.14864, -0.37659, 0.29254, -0.40274, 0.59584, -0.95916, -0.15567, 0.76168, 0.088067, 0.6846, -0.39884, 0.01839, -0.025578, -0.67058, 0.51273, 0.78468, -0.12751, 0.46849, -1.3988, -0.73757, -0.11943, 1.5621, -0.66478, 3.3061, 0.48236, -0.73916, -0.2679, -0.47081, -0.18434, 0.36776, -0.51161, 0.060674, -0.087342, -0.20121, -0.53426, 0.45001, -0.015149, -0.070133, 0.35922, -0.25262, 0.18598, 0.12959, 0.87333)] (of class org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema)
[error] at Main$$anonfun$2.apply(Main.scala:97)
[error] at Main$$anonfun$2.apply(Main.scala:97)
[error] at scala.collection.Iterator$$anon$11.next(Iterator.scala:410)
[error] at org.apache.spark.util.collection.ExternalSorter.insertAll(ExternalSorter.scala:193)
[error] at org.apache.spark.shuffle.sort.SortShuffleWriter.write(SortShuffleWriter.scala:63)
[error] at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:96)
[error] at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:53)
[error] at org.apache.spark.scheduler.Task.run(Task.scala:109)
[error] at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:345)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] at java.base/java.lang.Thread.run(Thread.java:844)
您可以使用以下方式切换列表视图项的更改:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
view.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
}
});
这使用关联的列表视图对象的属性来检查是否已选择该项目,然后根据此颜色进行更改。我猜想您也想“不变”颜色。这样的事情可能就是您所需要的。