here ia an application where i displaying some text with image background but it got changes position
automatically when notifieddatasetchanged() is called, please help me how to fixed it constant position ,below is my code. thanks you
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;
}
here is the code for updating gridview in every 20sec
//=============Refreshing 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 );
}
}
It’s happening like this because you are giving the if condition. It’s because at the first time only
convertviewgets assigned. For the second time it’s not entering into the if condition.And you have to execute the codes within the if. So just remove the if condition, it will work properly.