gpt4 book ai didi

android - gridview 在 notifiedDatasetChangedCalled 时自动更改位置?

转载 作者:行者123 更新时间:2023-11-29 22:21:00 25 4
gpt4 key购买 nike

这是一个应用程序,我在其中显示一些带有图像背景的文本,但它的位置发生了变化当调用 notifieddatasetchanged() 时自动,请帮助我如何固定它的固定位置,下面是我的代码。谢谢你

 public View getView(final int position, View convertView, ViewGroup parent) {
//ImageView imageView;
View v;
TextView tv = null;
if (convertView == null) {


LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.show_table_gridview, null);
tv = (TextView)
v.findViewById(R.id.tab_num);
tv.setText(""+position+1));

tv.setTextColor(Color.BLACK);
HashMap<Integer, List<OrderlistData>> orederMap1 = ConText
.getTotlaMap();
List<OrderlistData> orderlist1 = new ArrayList<OrderlistData>();
Set<Integer> keySet1 = orederMap1.keySet();
if (keySet1.contains(position))
orderlist1 = orederMap1.get(position);

if (orderlist1.isEmpty()){

}
else{
tv.setBackgroundColor(Color.CYAN);
}
}
else {
v = convertView;
}
/**
* Code for changing background if data is content
*/
return v;
}

这是每 20 秒更新一次 gridview 的代码
//=============刷新gridview ==============

  private class UpdateGridview extends AsyncTask<Context, Integer, String>
{

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

int i = 0;
while (i < 10) {
try {
Thread.sleep(30000);
Message msg = handler.obtainMessage();
handler.sendMessage(msg);

i++;
} catch (Exception e) {
Log.i("makemachine", e.getMessage());
}
}
return "COMPLETE!";
}

private final Handler handler = new Handler() {
public void handleMessage(Message msg) {

getCurrent_orderlist_StatusFromServer();
gridadapter.notifyDataSetChanged();

System.out
.println("i called notifyDataSetChanged()=======================");
}
};


// -- gets called just before thread begins
@Override
protected void onPreExecute()
{
Log.i( "makemachine", "onPreExecute()" );
super.onPreExecute();

}


@Override
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);

}

// -- called if the cancel button is pressed
@Override
protected void onCancelled()
{
super.onCancelled();
Log.i( "makemachine", "onCancelled()" );

}

// -- called as soon as doInBackground method completes
// -- notice that the third param gets passed to this method
@Override
protected void onPostExecute( String result )
{
super.onPostExecute(result);
Log.i( "makemachine", "onPostExecute(): " + result );

}

最佳答案

之所以会这样,是因为您给出了 if 条件。这是因为第一次只有 convertview 被分配。它第二次没有进入 if 条件。而且你必须执行 if 中的代码。所以只要去掉 if 条件,它就会正常工作。

关于android - gridview 在 notifiedDatasetChangedCalled 时自动更改位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7185775/

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