1

Hi I am developing android application in which I am using grid view. I want to updated grid item dynamically.My grid item contains one title text. I tried to do it like this but it is not working for me.

 ((Activity)context).runOnUiThread(new Runnable()
    {
        public void run()
        {
            Debug.print("this is update progress inside thread  ...");

            owner.setText("Uploading...");

            invalidate();
            requestLayout();
        }
    });

So in above code its printing debug statement. But not updating my owner text which is inside grid item.

I tried this also...

 Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            owner.setText("Uploading...");
        }
    };
    handler.sendEmptyMessage(0);
nilkash
  • 7,408
  • 32
  • 99
  • 176
  • Could you please add a little bit more of your code? It's not clear what is "owner", where do you initialize it and where is all this running. – Paul Freez Apr 06 '15 at 07:20

4 Answers4

0

So in above code its printing debug statement. But not updating my owner text which is inside grid item.

I think it's textview does not reference to your item in grid adapter. You can check it by set tag when init and getTag() inside runonUIThread method.

Let check this textview is local or global variable. If global, it's only reference to the last item - then check the last item change? OK if it's not. Let post full ur code.

famfamfam
  • 396
  • 3
  • 8
  • 31
  • I am inside custom view class where I have only context reference. Not able to get activity. I tried with removing invalidate and requestLayout but that is not working for me. – nilkash Apr 06 '15 at 06:53
  • It is updating multiple grid items except last one added. – nilkash Apr 06 '15 at 07:17
0
runOnUiThread(new Runnable() {
    @Override
    public void run() {
        Debug.print("Updating UI ...");
        owner.setText("Uploading ...");
        invalidate();
        requestLayout();
    }
});
David
  • 3,392
  • 3
  • 36
  • 47
Arjun Prakash
  • 669
  • 9
  • 23
0

Try to refresh your adapter which you used to load the grid item. Either you could use invalidateViews() method or adapter.notifyDataSetChanged()

This will help you to resolve your issue.

Happy coding..

Srinivasan
  • 4,481
  • 3
  • 28
  • 36
  • Srinivasan what I am actually doing I am adding items to grid dynamically. Which is working properly. After that I am uploading data to server. I want to show that status to my grid item. If I add multiple item in grid its working proper except last one. And if I upload single record it's not working. That mean for one item it is not working. The record which added first. – nilkash Apr 06 '15 at 06:58
  • Ok...I understood nilkash. Please tell me how do you find the 'owner' textview from the Grid.May be the problem on finding the view to show the 'Uploading' text. And one more thing, please tell me whether the data uploaded to server or not if the grid having single item? – Srinivasan Apr 06 '15 at 07:07
0

Check if you have any Thread.sleep() in your code that might be blocking the UI.

live-love
  • 48,840
  • 22
  • 240
  • 204