здесь ia приложение, в котором я показываю некоторый текст с фоном изображения, но он автоматически меняет позицию, когда 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;
}
вот код для обновления gridview в каждые 20 сек.
//============= Обновление 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
только convertview
. Второй раз он не входит в условие if. И вам нужно выполнить коды внутри if. Поэтому просто удалите условие if, оно будет работать правильно.