gpt4 book ai didi

android - ListView getChildAt() 为空

转载 作者:行者123 更新时间:2023-11-29 19:26:35 25 4
gpt4 key购买 nike

我的代码

public class Products extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.addproducts);
FillList fillList = new FillList();
fillList.execute("");

}
public class FillList extends AsyncTask<String, String, String> {

List<Map<String, String>> prolist = new ArrayList<Map<String, String>>();
@Override
protected void onPreExecute() {

}

@Override
protected void onPostExecute(String r) {


String[] from = { "E","D", "C", "B","A"};
int[] views = { R.id.lblMondeh,R.id.lblBes,R.id.lblBed,R.id.lblSharh,R.id.lblDate};
final SimpleAdapter ADA = new SimpleAdapter(Products.this,
prolist, R.layout.lsttemplate, from,
views);
lstSoratHesab.setAdapter(ADA);
lstSoratHesab.setVisibility(View.VISIBLE);

if(lstSoratHesab.getChildAt(0-lstSoratHesab.getFirstVisiblePosition())!=null)//all time this line is null
lstSoratHesab.getChildAt(0).setBackgroundColor(Color.parseColor("#ff00aa63"));//i want change color first row

}

@Override
protected String doInBackground(String... params) {

Map<String, String> datanum = new HashMap<String, String>();

datanum.put("E", "e");
datanum.put("D", "d");
datanum.put("C", "c");
datanum.put("B", "b");
datanum.put("A", "a");
prolist.add(datanum);

}
}
}

我想为第一行设置背景颜色。

为什么 lstSoratHesab.getChildAt(0-lstSoratHesab.getFirstVisiblePosition())lstSoratHesab.getChildAt(0) 所有时间都为空?

但是 ListView 有 20 行

enter image description here

最佳答案

getChildAt(0) 将检索第一行元素,但您需要在线程中获取它,以便让布局在屏幕上显示的时间,可以设置为:

lstSoratHesab.post(new Runnable() {
@Override
public void run() {
if (lstSoratHesab.getChildAt(0) != null) {
lstSoratHesab.getChildAt(0)
.setBackgroundColor(Color.parseColor("#ff00aa63"));
}
}
});

关于android - ListView getChildAt() 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41268158/

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