This is my Card Place and winner Card Animation Code inside
PlayerView.java class
private void startCardAnimation(int placeCardX, int placeCardY, int sourceX, int sourceY, ImageView placedCard, int cardId) {
placedCard.setImageDrawable(Card.cardImageNameFromId(mContext, cardId));
Animation animation = null;
if (placedCard.getId() == R.id.player_destination_card4)
animation= AnimationUtils.loadAnimation(mContext,R.anim.from_righttoleft);
else if (placedCard.getId() == R.id.player_destination_card1)
animation= AnimationUtils.loadAnimation(mContext,R.anim.from_bottomtotop);
else if (placedCard.getId() == R.id.player_destination_card2)
animation= AnimationUtils.loadAnimation(mContext,R.anim.from_lefttoright);
else if (placedCard.getId() == R.id.player_destination_card3)
animation= AnimationUtils.loadAnimation(mContext,R.anim.from_toptobottom);
placedCard.startAnimation(animation);
deleteCache(mContext);
}
public void placeCardAnimation(int cardId, ImageView placedCard) {
player_source_card.setVisibility(INVISIBLE);
placedCard.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
placedCard.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int[] locations = new int[2];
placedCard.getLocationOnScreen(locations);
placeCardX1 = locations[0];
placeCardY1 = locations[1];
startCardAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
}
});
player_source_card.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
player_source_card.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int[] locations = new int[2];
player_source_card.getLocationOnScreen(locations);
sourceCardX1 = locations[0];
sourceCardY1 = locations[1];
startCardAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
}
});
}
private void startWinnerAnimation(int placeCardX, int placeCardY, int sourceX, int sourceY, ImageView placedCard, int cardId) {
placedCard.setImageDrawable(Card.cardImageNameFromId(mContext, cardId));
TranslateAnimation animation = new TranslateAnimation(sourceX - placeCardX, 0, sourceY - placeCardY, 0);
animation.setDuration(2000);
animation.setFillAfter(true);
animation.setInterpolator(new ReverseInterpolator());
placedCard.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
placedCard.clearAnimation();
placedCard.setVisibility(GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
}
public void WinnerCardAnimation(int cardId, ImageView placedCard) {
player_source_card.setVisibility(INVISIBLE);
placedCard.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
placedCard.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int[] locations = new int[2];
placedCard.getLocationOnScreen(locations);
placeCardX1 = locations[0];
placeCardY1 = locations[1];
startWinnerAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
}
});
player_source_card.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
player_source_card.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int[] locations = new int[2];
player_source_card.getLocationOnScreen(locations);
sourceCardX1 = locations[0];
sourceCardY1 = locations[1];
startWinnerAnimation(placeCardX1, placeCardY1, sourceCardX1, sourceCardY1, placedCard, cardId);
}
});
}
Inside this code we will get current all user data and through card one by one and fetch detail of current table and user detail PlayCardTable.java class
private void getCurrentTableStatus() {
JSONObject jsonObject = new JSONObject();
if (ConstantData.isInternetAvailable(PlayCardTable.this))
try {
jsonObject.put(RequestParams.TABLEID, tableId);
} catch (JSONException e) {
e.printStackTrace();
}
ApplicationClass app = (ApplicationClass) getApplication();
app.mSocket.emit(RequestParams.GET_CURRENT_TABLE_STATUS, jsonObject);
app.mSocket.on(RequestParams.GET_CURRENT_TABLE_STATUS + "Reply" + tableId, args -> {
try {
String TableStatus = (String) args[0];
Log.d("CurrentTableStatus---", "" + TableStatus);
tablestatusjsonobject = new JSONObject(TableStatus);
Table tempTableStatus = Table.getParseStatus(tablestatusjsonobject, userId);
if (tempTableStatus.getTableId() == tableId) {
TIMERCOUNT = 0;
tableStatus = tempTableStatus;
Log.d("CurrentTableStatus---", "" + tableStatus.getTableId());
runOnUiThread(() -> {
if (playerImageViewByPlayerId == null
|| (playerImageViewByPlayerId.size() != tableStatus.getNoOfPlayers())) {
initplayerImageViewByPlayerId();
}
int joinPlayerWithTable = tableStatus.getPlayers().size();
if (tableStatus.getNoOfPlayers() == joinPlayerWithTable) {
if (tableStatus.getWinnerUserId() != 0 && tableStatus.getWinnerPoints() != 0) {
app.mSocket.off(RequestParams.GET_CURRENT_TABLE_STATUS + "Reply");
Log.d("User Id ", "Winner User Id : " + tableStatus.getWinnerUserId());
Log.d("Winner Point", "Winner Point: " + tableStatus.getWinnerPoints());
loadFragments(new ScoreBoardFragment(), "");
} else {
ConstantData.progressclose();
updatePlayerCard();
setUpPlayerData();
playturn();
if (!(tableStatus.isBidDone())) {
bidturn();
} else if (tableStatus.getMainSuit() != null && tableStatus.getMainSuit().equalsIgnoreCase("")) {
selctSuitAndFriends();
} else {
oldRoundCards = RoundCard.getOldRoundCardData(this);
if (oldRoundCards == null || oldRoundCards.isEmpty()) {
RoundCard.setOldRoundCardData(tableStatus.getRoundCards(), this);
oldRoundCards = RoundCard.getOldRoundCardData(this);
}
Log.d("ThrowCard---round", "" + tableStatus.getRoundCards().size() + "," + oldRoundCards.size());
RoundCard updatedThrownCards = getUpdatedThrownCards(oldRoundCards, tableStatus.getRoundCards());
if (updatedThrownCards != null && updatedThrownCards.getUserId() != userId) {
Objects.requireNonNull(playerImageViewByPlayerId.get(updatedThrownCards.getUserId())).placeCardAnimation(updatedThrownCards.getCardId(), placedCardPosition.get(updatedThrownCards.getUserId()));
Log.d("animation card-", updatedThrownCards.getCardId() + "," + updatedThrownCards.getUserId());
}
RoundCard.setOldRoundCardData(tableStatus.getRoundCards(), this);
maxBid();
partner();
selectPartnerCard();
setHukumData();
setAlreadyThrownCardOnTable(tableStatus.getRoundCards());
setUpClickForOtherPlayer();
}
}
} else {
ConstantData.progressclose();
ConstantData.Displayprogress(PlayCardTable.this, "Please Wait Players Joining With This Table");
}
});
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("CurrentTableStatus---ex", e.toString());
}
});
}
This code For animation inside PlayCardTable.java
private void setAlreadyThrownCardOnTable(List<RoundCard> roundCards) {
try {
roundState = RoundState.getRoundState(PlayCardTable.this);
if (roundState != null) {
if (roundCards.size() == tableStatus.getNoOfPlayers()) {
if (roundState.getRoundAnimationState().equals(RoundAnimationRunning)) {
return;
} else if (roundState.getRoundAnimationState().equals(RoundInComplete)) {
roundState.setRoundAnimationState(RoundComplete);
roundState.save(this);
} else if (roundState.getRoundAnimationState().equals(RoundAnimationComplete)) {
roundCards.clear();
}
}
}
if (roundCards.size() != tableStatus.getNoOfPlayers()) {
if (roundCards.size() > 0) {
roundState = new RoundState(roundCards.get(0).getRoundNo(), RoundInComplete);
roundState.save(this);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
if (roundState != null) {
if (roundState.getRoundAnimationState().equals(RoundComplete)) {
new Handler().postDelayed(() -> {
try {
if (!tableStatus.getRoundCards().isEmpty()) {
if (tableStatus.getRoundCards().get(0).getRoundGoesTo() != 0) {
roundState.setRoundAnimationState(RoundAnimationRunning);
roundState.save(this);
placedCard4.setRotation(90);
placedCard2.setRotation(90);
for (int i = 0; i < placedCardPosition.size(); i++) {
playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
.WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard1);
playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
.WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard2);
playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
.WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard3);
playerImageViewByPlayerId.get(tableStatus.getRoundCards().get(0).getRoundGoesTo())
.WinnerCardAnimation(tableStatus.getRoundCards().get(i).getCardId(), placedCard4);
}
new Handler().postDelayed(() -> {
roundState.setRoundAnimationState(RoundAnimationComplete);
roundState.save(PlayCardTable.this);
clearThrownCardOnTable();
}, 5000);
}
}
} catch (Exception ex) {
Log.e("", ex.toString());
}
roundCards.clear();
}, 1000);
}
}
if (roundCards.isEmpty())
clearThrownCardOnTable();
else {
for (int i = 0; i < roundCards.size(); i++) {
Drawable res = Card.cardImageNameFromId(PlayCardTable.this, roundCards.get(i).getCardId());
ImageView placedCardAsPerUserId = placedCardPosition.get(roundCards.get(i).getUserId());
if (placedCardAsPerUserId != null) {
placedCardAsPerUserId.setVisibility(View.VISIBLE);
placedCardAsPerUserId.setImageDrawable(res);
}
}
}
}
I am working on a card game in that I'm getting the issue in animation while placing the card in the game. In my case, there are 4 players who are playing game together. Turn by turn user will place card according , place card animation working fine until 4-5 turn , but as playing more round animation getting hang and after 7-8 round its totally stop working ,and after clear app from recent and again resume game than it's again working fine, again after 4-5 turn its getting hang, Here I attached video of my game, animation hanging and related code Please help me to resolve this animation issue.
Please Refer link for ios game animation we need that type of animation in Android
I would like to add some ImageViews to a RelativeLayout view.
The code that I'm using is as follows:
Thread thread = new Thread(new Runnable() {
ArrayList<ImageView> icons = new ArrayList<ImageView>();
#Override
public void run() {
for (int i = 0; i < 20; i++) {
ImageView imageView1 = new ImageView(G.context);
imageView1.setImageResource(R.drawable.music_icon);
imageView1.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
imageView1.getLayoutParams().width = (int) convertDpToPixel(20);
imageView1.getLayoutParams().height = (int) convertDpToPixel(20);
icons.add(imageView1);
Log.i("LOG", "Icons Size: " + icons.size());
Log.i("LOG", "I: " + i);
relativeLayout.addView(icons.get(i));
icons.get(i).startAnimation(animationMusic);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
thread.start();
The first time the loop runs fine, but the second time there's an error in the line:
relativeLayout.addView(icons.get(i));
Where is the problem?
One major problem is manipulating the view (e.g. adding a View) from a background thread. You can get similar async behavior by making use of Android's AsyncTask objects and do any UI manipulation from the onPostExecute method.
Without know more about what you're doing, it's hard to find a solution that will work for you. I was mainly pointing out a primary issue with your code.
Here is an attempt to rewrite your code in a way that might work better in an Android environment:
public void addImageViews() {
for(int i = 0; i < 20; i++) {
asyncAdd(i, G.context);
}
}
protected void asyncAdd(final int index, final Context c) {
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(3000 * index);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void result) {
relativeLayout.addView(generateImageView(c));
}
}.execute();
}
protected ImageView generateImageView(Context c) {
ImageView imageView1 = new ImageView(c);
imageView1.setImageResource(R.drawable.music_icon);
imageView1.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
imageView1.getLayoutParams().width = (int) convertDpToPixel(20);
imageView1.getLayoutParams().height = (int) convertDpToPixel(20);
return imageView1;
}
I am building a simple game (using Java and android xml) and I want to refresh a TextView with a numeric value as often as possible (let's say 5-10 times a second)
Questions:
Is there a better way to show a numeric value refreshing more than once a second?
How to do it efficiently?
My current code:
void textViewRefresher() {
Thread t = new Thread() {
#Override
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(100);
runOnUiThread(new Runnable() {
#Override
public void run() {
DecimalFormat format = new DecimalFormat("#.#");
format.setDecimalSeparatorAlwaysShown(false);
bankValue = bankValue + 0.1 * perSecondValue;
String truncatedBank = format.format(bankValue);
bankText.setText(truncatedBank);
totalValue = totalValue + 0.1 * perSecondValue;
String truncatedTotal = format.format(totalValue);
totalText.setText("Total: " + truncatedTotal);
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
}
I have custom ImageView for animated GIF image. i want to show GIF image, I tried but in this case it is contain url in Async instead I want to show GIF image from raw folder without using Glide. Anyone have any idea how to show image? Please guyz help to solve this problem!!!
I tried this for set raw file
new GifStaticData() {
#Override
protected void onPostExecute(Resource drawable) {
super.onPostExecute(drawable);
gifImageView.setImageResource(R.raw.earth_tilt_animation);
// Log.d(TAG, "GIF width is " + gifImageView.getGifWidth());
// Log.d(TAG, "GIF height is " + gifImageView.getGifHeight());
}
}.execute(R.raw.earth_tilt_animation);
GifStaticData.java
public class GifStaticData extends AsyncTask<Resource, Void, Resource> {
private static final String TAG = "GifDataDownloader";
#Override protected Resource doInBackground(final Resource... params) {
final Resource gifUrl = params[0];
if (gifUrl == null)
return null;
try {
// return ByteArrayHttpClient.get(gifUrl);
return gifUrl;
} catch (OutOfMemoryError e) {
Log.e(TAG, "GifDecode OOM: " + gifUrl, e);
return null;
}
}
}
GifImageView.java
public class GifImageView extends ImageView implements Runnable {
private static final String TAG = "GifDecoderView";
private GifDecoder gifDecoder;
private Bitmap tmpBitmap;
private final Handler handler = new Handler(Looper.getMainLooper());
private boolean animating;
private boolean shouldClear;
private Thread animationThread;
private OnFrameAvailable frameCallback = null;
private long framesDisplayDuration = -1L;
private OnAnimationStop animationStopCallback = null;
private final Runnable updateResults = new Runnable() {
#Override
public void run() {
if (tmpBitmap != null && !tmpBitmap.isRecycled()) {
setImageBitmap(tmpBitmap);
}
}
};
private final Runnable cleanupRunnable = new Runnable() {
#Override
public void run() {
tmpBitmap = null;
gifDecoder = null;
animationThread = null;
shouldClear = false;
}
};
public GifImageView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public GifImageView(final Context context) {
super(context);
}
public void setBytes(final byte[] bytes) {
gifDecoder = new GifDecoder();
try {
gifDecoder.read(bytes);
gifDecoder.advance();
} catch (final OutOfMemoryError e) {
gifDecoder = null;
Log.e(TAG, e.getMessage(), e);
return;
}
if (canStart()) {
animationThread = new Thread(this);
animationThread.start();
}
}
public long getFramesDisplayDuration() {
return framesDisplayDuration;
}
/**
* Sets custom display duration in milliseconds for the all frames. Should be called before {#link
* #startAnimation()}
*
* #param framesDisplayDuration Duration in milliseconds. Default value = -1, this property will
* be ignored and default delay from gif file will be used.
*/
public void setFramesDisplayDuration(long framesDisplayDuration) {
this.framesDisplayDuration = framesDisplayDuration;
}
public void startAnimation() {
animating = true;
if (canStart()) {
animationThread = new Thread(this);
animationThread.start();
}
}
public boolean isAnimating() {
return animating;
}
public void stopAnimation() {
animating = false;
if (animationThread != null) {
animationThread.interrupt();
animationThread = null;
}
}
public void clear() {
animating = false;
shouldClear = true;
stopAnimation();
handler.post(cleanupRunnable);
}
private boolean canStart() {
return animating && gifDecoder != null && animationThread == null;
}
public int getGifWidth() {
return gifDecoder.getWidth();
}
public int getGifHeight() {
return gifDecoder.getHeight();
}
#Override public void run() {
if (shouldClear) {
handler.post(cleanupRunnable);
return;
}
final int n = gifDecoder.getFrameCount();
do {
for (int i = 0; i < n; i++) {
if (!animating) {
break;
}
//milliseconds spent on frame decode
long frameDecodeTime = 0;
try {
long before = System.nanoTime();
tmpBitmap = gifDecoder.getNextFrame();
frameDecodeTime = (System.nanoTime() - before) / 1000000;
if (frameCallback != null) {
tmpBitmap = frameCallback.onFrameAvailable(tmpBitmap);
}
if (!animating) {
break;
}
handler.post(updateResults);
} catch (final ArrayIndexOutOfBoundsException | IllegalArgumentException e) {
Log.w(TAG, e);
}
if (!animating) {
break;
}
gifDecoder.advance();
try {
int delay = gifDecoder.getNextDelay();
// Sleep for frame duration minus time already spent on frame decode
// Actually we need next frame decode duration here,
// but I use previous frame time to make code more readable
delay -= frameDecodeTime;
if (delay > 0) {
Thread.sleep(framesDisplayDuration > 0 ? framesDisplayDuration : delay);
}
} catch (final Exception e) {
// suppress any exception
// it can be InterruptedException or IllegalArgumentException
}
}
} while (animating);
if (animationStopCallback != null) {
animationStopCallback.onAnimationStop();
}
}
public OnFrameAvailable getOnFrameAvailable() {
return frameCallback;
}
public void setOnFrameAvailable(OnFrameAvailable frameProcessor) {
this.frameCallback = frameProcessor;
}
public interface OnFrameAvailable {
Bitmap onFrameAvailable(Bitmap bitmap);
}
public OnAnimationStop getOnAnimationStop() {
return animationStopCallback;
}
public void setOnAnimationStop(OnAnimationStop animationStop) {
this.animationStopCallback = animationStop;
}
public interface OnAnimationStop {
void onAnimationStop();
}
#Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
clear();
}
}
I had to play and pause the Gif image Glide - Cannot stop gif onClick- Getting TransitionDrawable instead of Animate/GifDrawable
The idea is to get drawable from view,checking if it is an instance of Gifdrawable and playing and pausing it.(Hoping the gif image is already playing)
Add this In OnClick of GifImageView
Drawable drawable = ((ImageView) v).getDrawable();
if (drawable instanceof GifDrawable) {
GifDrawable animatable = (GifDrawable) drawable;
if (animatable.isRunning()) {
animatable.stop();
} else {
animatable.start();
}
}
I found the solution of above problem using GifMovieView!!!
GifMovieViewer.java
public class GifMovieViewer extends Activity {
private Button btnStart;
private GifMovieView gif1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gif_movie_viewer);
gif1 = (GifMovieView) findViewById(R.id.gif1);
btnStart = (Button) findViewById(R.id.btnStart);
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
gif1.setMovieResource(R.drawable.earth_tilt_animation);
//for pause
// gif1.setPaused(gif1.isPaused());
}
});
}
public void onGifClick(View v) {
GifMovieView gif = (GifMovieView) v;
gif.setPaused(!gif.isPaused());
}
}
I am working on TCP socket. I receive data for every 1 sec from server and I need to display it on screen in ListView.
For this I used AsyncTask.
But I am frequently getting IllegalStateException error
My code:
Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
#Override
public void run() {
finalizer = new Runnable() {
public void run() {
try {
if (navBool) {
runOnUiThread(new Runnable() {
public void run() {
new RetriveStock().execute(); // AsyncTask.
}
});
}
} catch (Exception e) {
}
}
};
handler.post(finalizer);
}
};
timer.schedule(doAsynchronousTask, 0, 1000);
// AsyncTask class
public class RetriveStock extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
message = client.clientReceive(1); // Here I receive data from server and stores it in "message" string variable.
printJson(); // FUNCTION WHICH UPDATE VALUES IN 'obj' OBJECT
runOnUiThread(new Runnable() {
#Override
public void run() {
updateList();// FUNCTION WHICH UPDATE THE LISTVIEW UI.
adb.notifyDataSetChanged();
}
});
return null;
}
#Override
protected void onCancelled() {
super.onCancelled();
}
#Override
protected void onPostExecute(Void result) {
if (adb != null) {
lv.invalidateViews();
lv.setAdapter(adb);
adb.notifyDataSetChanged();
lv.requestLayout();
}
super.onPostExecute(result);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
// function which update values in JSON.
public void printJson() {
try {
JSONArray jsonArray = new JSONArray(message);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json = jsonArray.getJSONObject(i);
String symbol = json.getString("Symbol_En");
User obj = new User();
boolean checkSymbol = false;
for (int j = 0; j < list.size(); j++) {
obj = list.get(j);
if (obj.getSymbol().equalsIgnoreCase(symbol)) {
checkSymbol = true;
break;
}
}
if (!checkSymbol) {
obj = new User();
obj.Symbol_En = json.getString("Symbol_En");
obj.Symbol_Ar = json.getString("Symbol_Ar");
obj.AskPrice = json.getString("Ask");
obj.BidPrice = json.getString("Bid");
obj.AskQuantity = json.getString("AskQuantity");
obj.High = json.getString("High");
obj.Low = json.getString("Low");
obj.Open = json.getString("Open");
obj.Close = json.getString("Close");
obj.PerChange = json.getString("PerChange");
obj.NetChange = json.getString("NetChange");
obj.Volume = json.getString("Volume");
obj.Ltp = json.getString("LTP");
obj.TimeStamp = json.getString("TimeStamp");
obj.symbolId = json.getString("Id");
list.add(obj);
} else {
obj.Symbol_En = json.getString("Symbol_En");
obj.AskPrice = json.getString("Ask");
obj.BidPrice = json.getString("Bid");
obj.High = high + "";
obj.Low = low + "";
obj.Open = json.getString("Open");
obj.Close = json.getString("Close");
obj.PerChange = json.getString("PerChange");
obj.NetChange = json.getString("NetChange");
obj.Volume = json.getString("Volume");
obj.Ltp = json.getString("LTP");
obj.TimeStamp = json.getString("TimeStamp");
obj.symbolId = json.getString("Id");
}
}
} catch (JSONException e1) {
e1.printStackTrace();
}
}
// function which update LISTVIEW UI.
public void updateList() {
adb = new ArrayAdapter<User>(DefaultMarketWatch.this,
R.layout.rssitemview, list) {
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
View view = convertView;
try {
if (null == view) {
LayoutInflater vi = (LayoutInflater) DefaultMarketWatch.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.rssitemview, null);
}
final User u = list.get(position);
if (null != u) {
final TextView title = (TextView) view
.findViewById(R.id.symbol);
final TextView persend = (TextView) view
.findViewById(R.id.persent);
final TextView ltp = (TextView) view
.findViewById(R.id.ltp);
final TextView high = (TextView) view
.findViewById(R.id.high);
final TextView low = (TextView) view
.findViewById(R.id.low);
final TextView persendBold = (TextView) view
.findViewById(R.id.persent_bold);
final TextView persendSup = (TextView) view
.findViewById(R.id.persent_sup);
ltp.setText(u.getLtp());
title.setText(u.getSymbol());
high.setText(u.getHigh());
low.setText(u.getLow());
persend.setText(u.getPerChange());
}
} catch (Exception e) {
e.printStackTrace();
}
return view;
}
};
}
Your log says
The content of the adapter is changed but listview did not receive notification. make sure content of your adapter is not modified from background thread but only from ui thread.
You have updateList() // FUNCTION WHICH UPDATE THE LISTVIEW UIin doInBackground. doInbackground is invoked on the background thread. You need to update ui on the Ui thread.
Use runOnUiThread which is method of activity or return result in doInbackground and update listview in onPostExecute