friends I am building an App for android and facing some problem in showing dynamically added TextViewer
my scenario is like this.
I am using ResulReceiver
to receive notification
and adding this result Dynamically in TextView
to display.When my activity is active I.e The application is keep open
till then it is working properly.
When my Activity is not in the Active
mode then I'm storing it to DB (SQLLITE)
, but when I come back to my Activity again then I can fetch data from DB and do the same thing like before,till now there is no problem.
But it starts as i receive new notification at that time is not able to append the new TextView
with the existing one dynamically,But when fro debugging purpose i use Toast it is showing properly.
Could you please help me out.
Thanks in Advance.
This is my code
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
// TODO Auto-generated method stub
String result = resultData.getString("notifyService");
CustomActionBar.controlNotifyImage(this,mActionBar);
ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1);
ComponentName componentInfo = taskInfo.get(0).topActivity;
if(!".activity.CatagoryChooserActivity".equals(componentInfo.getShortClassName()) ){
notifyInfo = new NotifyInfo();
notifyInfo.setNotifyPk(100000+new Long(CreateOrderService.notifyCount.get()));
notifyInfo.setNotifyTxt(result);
notifyInfo.setNotifyDate(new Date().toString());
notifyInfo.setNotifyTime(new Date().toGMTString());
SellerNotifyDB sellerNotifydb = SellerNotifyDB.getInstance(context);
sellerNotifydb.addNotification(notifyInfo);
Toast.makeText(this,"Notify :: "+CreateOrderService.notifyCount.get(),Toast.LENGTH_LONG).show();
}
else {
runOnUiThread(new UpdateUI(result));
}
}
class UpdateUI implements Runnable
{
String updateString;
public UpdateUI(String updateString) {
this.updateString = updateString;
}
public void run() {
// txtview.setText(updateString);
createNotifyLatout(updateString);
}
private void createNotifyLatout(String result) {
//final ArrayList<TextView> addrTextList = new ArrayList<TextView>();
addrLinearLayout = (LinearLayout) findViewById(R.id.dashboardLayout);
TextView addrTextView = new TextView(context);
LinearLayout addrLayout = new LinearLayout(context);
addrLayout.setPadding(2, 0, 2, 0);
addrLayout.setOrientation(LinearLayout.HORIZONTAL);
ImageView editImgBtn = new ImageView(context);
editImgBtn.setId(700 + CreateOrderService.notifyCount.get());
editImgBtn.setImageDrawable(getResources().getDrawable(R.drawable.takeorder));
editImgBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
editImgBtn.setLayoutParams((new LinearLayout.LayoutParams(100,
40, 1.0f)));
ImageView deltImgBtn = new ImageView(context);
deltImgBtn.setId(8000 + CreateOrderService.notifyCount.get());
deltImgBtn.setLayoutParams((new LinearLayout.LayoutParams(100,
50, 1.0f)));
deltImgBtn.setPadding(0, 0, 0, 10);
deltImgBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
deltImgBtn.setImageDrawable(getResources().getDrawable(R.drawable.cancelorder));
addrTextView.setPadding(2, 5, 0, 0);
addrTextView.setText(Html.fromHtml("<br><br>" + result + "<br><br>"));
addrTextView.setLayoutParams((new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)));
addrTextView.setMaxEms(10);
// registerForContextMenu(addrTextView);
addrLayout.setBackgroundColor(getResources().getColor(R.color.banarColor));
addrLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
addrLayout.setDividerDrawable(getResources().getDrawable(R.drawable.divider));
addrTextView.setTextColor(getResources().getColor(R.color.backgroundColor));
addrTextView.setBackgroundDrawable(getResources().getDrawable(R.drawable.backg_txt));
addrLayout.addView(editImgBtn);
addrLayout.addView(deltImgBtn);
// addrTextList.add(addrTextView);
addrLinearLayout.addView(addrTextView);
addrLinearLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.border_img));
addrLinearLayout.addView(addrLayout);
Toast.makeText(context,"Notify Open :: "+CreateOrderService.notifyCount.get()+"=@@=="+result,Toast.LENGTH_LONG).show();
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
CustomActionBar.controlNotifyImage(this,mActionBar);
//Toast.makeText(context,"#####",Toast.LENGTH_LONG).show();
SellerNotifyDB sellerNotifydb = SellerNotifyDB.getInstance(context);
sellerNotifydb.deleteNotification();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
CustomActionBar.controlNotifyImage(this,mActionBar);
SellerNotifyDB sellerNotifydb = SellerNotifyDB.getInstance(context);
ArrayList notifyInfoList = sellerNotifydb.getNotification();
if(notifyInfoList instanceof ArrayList && notifyInfoList.size() > 0)
for (int i=0;i<notifyInfoList.size();i++){
//createNotifyLatout(((NotifyInfo)notifyInfoList.get(i)).getNotifyTxt());
test = ((NotifyInfo)notifyInfoList.get(i)).getNotifyTxt();
runOnUiThread(new UpdateUI(test));
}
}