gpt4 book ai didi

android - 在 ANDROID 布局中动态添加 TextView

转载 作者:行者123 更新时间:2023-11-29 16:02:42 25 4
gpt4 key购买 nike

我想动态创建两个 TextView 并在名为 activity_ranking 的 linearLayout 中显示它们。我试了一下,LogCat 说问题出在这一行:“ranking.addView(fecha);”你知道会发生什么吗?谢谢!

public void listarPuntuaciones(){

LinearLayout ranking = (LinearLayout)findViewById(R.layout.activity_ranking);


for(int i=0; i<puntuaciones.size(); i++){


String aux[]=this.puntuaciones.elementAt(i).split(";");

TextView fecha = new TextView(this);
Log.i(aux[0],"aux0");
fecha.setText(aux[0]);
ranking.addView(fecha);

TextView puntos = new TextView(this);
Log.i(aux[1],"aux1");
puntos.setText(aux[1]);
ranking.addView(puntos);
}
}

最佳答案

我猜 ranking 为 null,因为当您尝试通过 ID 查找它时,您应该将 R.id.layout_id 作为参数。

here

关于android - 在 ANDROID 布局中动态添加 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22567064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com