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));
}
}
I think you need to stop your existing running service.
Keep your Existing TextView in a LinearLayout and then generate a TextView And add to LinearLayout. See this
Related
I am trying to extract text from a PDF file using MuPDF library in Android platform.
Is it possible to extract text within a rectangle specified by coordinates (left, top, right, bottom)?
Note: I didn't compile the library from source. I am using compiled libraries which is distributed in https://github.com/libreliodev/android.
yeah sure
here is the way you can do.
1.GeneratedText activity
public class GeneratedText extends Activity {
private Button close;
private Button clear;
private TextView tv;
private String data;
String text = "";
Intent i;
Context mContext;
// MuPDFPageView pdfview = new MuPDFPageView(mContext, null, null);
private EditText edit;
private Button undo;
public static GeneratedText screen;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generated_text);
close = (Button)findViewById(R.id.close);
clear = (Button)findViewById(R.id.clear);
tv = (TextView)findViewById(R.id.text1);
edit = (EditText)findViewById(R.id.edit);
undo = (Button)findViewById(R.id.undo);
undo.setEnabled(false);
i = getIntent();
data = i.getStringExtra("data");
tv.setText(data);
String mypattern = "Name and address of the Employee \n";
Pattern p = Pattern.compile(mypattern,Pattern.DOTALL);
if(data.matches(mypattern))
{
System.out.println("Start Printing name");
}
else
//do nothing
edit.setText(data);
System.out.println("hello user "+"/n"+"user1"+ "\n"+ "user2");
SharedPreferences pref = getSharedPreferences("key", 0);
SharedPreferences.Editor editor = pref.edit();
editor.putString("text", data);
editor.commit();
clear.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv.setText("");
edit.setText("");
undo.setEnabled(true);
}
});
close.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
undo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String value = "";
SharedPreferences pref = getSharedPreferences("key", 0);
value = pref.getString("text", value);
edit.setText(value);
tv.setText(value);
undo.setEnabled(false);
}
});
}
}
1. now in mupdfactivity write this
public void Showtext( )
{
destroyAlertWaiter();
core.stopAlerts();
MuPDFPageView pdfview = new MuPDFPageView(MuPDFActivity.this, core, null);
String data = "";
pdfview.setFocusable(true);
data = pdfview.getSelectedText();
Intent i = new Intent(getApplicationContext(),GeneratedText.class);
i.putExtra("data",data);
startActivity(i);
}
call Showtext in OnAcceptButtonClick
and you will get your text.
Yes it is possible to extract text from PDF document with the help of MuPDF library. There is method called text() in mupdf.c which is defined in MuPDFCore.java which returns the text of the page. You need to call that method by page wise.
Steps:
1. gotopage(pagenumber)
2. text()
While click the button i have added a checkbox, finally need to get the all checked checkbox value by means of clicking submit button,
This is my code
mIncrementButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(20, 0, 0, 0);
CheckBox checkbox = new CheckBox(MainActivity.this);
checkbox.setLayoutParams(params);
mAllText.add(checkbox);
checkbox.setText("Checkbox" + j);
checkboxlayout.addView(checkbox);
j++;
Log.d("j", "--->" + j);
}
});
mGetTheVlue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("Inside Button", "Inside Burron" + mAllText.size());
for (int i = 0; i < mAllText.size(); i++) {
CheckBox check = mAllText.get(i);
if (check.isChecked()) {
AllCheckbox.add(check.getText().toString());
}
}
}
});
Now i need to check whether all checkbox are checked and need to get the values,
Dont know whether this question is so old or not. but i dint get any solution from google kindly help to get the solution.
Thanks in advance.
Also you don't need to store all CheckBox in Collection. You can just get the child views from layout and check each of them if it is CheckBox.
mGetTheVlue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("Inside Button", "Inside Burron" + checkboxlayout.getChildCount());
for(int i=0; i<checkboxlayout.getChildCount(); i++) {
View nextChild = checkboxlayout.getChildAt(i);
if(nextChild instanceOf CheckBox)
{
CheckBox check = (CheckBox) nextChild;
if (check.isChecked()) {
AllCheckbox.add(check.getText().toString());
}
}
}
}
});
BELOW IS MY CODE. This code is working, but I want to get the value of the display image in array to test, if the display country is correct. Please help me . I'm stuck in this activity. Thanks for all help .
public class MainActivity extends Activity implements OnClickListener {
private boolean blocked = false;
private Handler handler = new Handler();
ViewFlipper flippy;
Button show;
TextView view;
int flags[] = { R.drawable.afghan, R.drawable.albania, R.drawable.algeria };
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.flipper);
flippy = (ViewFlipper) findViewById(R.id.viewFlipper1);
show = (Button) findViewById(R.id.button1);
view = (TextView) findViewById(R.id.textView1);
for (int i = 0; i < flags.length; i++) {
setflipperimage(flags[i]);
}
}
private void setflipperimage(int i) {
// TODO Auto-generated method stub
Log.i("Set Filpper Called", i + "");
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(i);
flippy.addView(image);
}
do not call this in loop,use this on click or on touch:
i+=1;
flippy.setDisplayedChild(flags[0]);
This will get used to get the current child id
viewFlipper.getDisplayedChild();
I am trying to get values from server and retrieved response from server, the details responsed from server are need to be displayed in a listview, i achieved that too, but while onitemclick process only first row in list view performs the click action but it is not performing for the remaining rows, how can i achieve it, dat is whatever the row and item i'm selecting it has to be processed by my code, here is my code for the reference, .........
public void userInterface() throws JSONException
{
if(json_user.get(0) != null)
{
downloadList1 = (ListView)findViewById(R.id.lvinbox);
populateData();
downloadList1.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
// TODO Auto-generated method stub
fma=(TextView)findViewById(R.id.src);
st=(TextView)findViewById(R.id.sub);
fma.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
String fm=fma.getText().toString();
String s=st.getText().toString();
Intent m = new Intent(getApplicationContext(), InActivity.class);
m.putExtra("f", fm);
m.putExtra("s", s);
startActivity(m);
}
});
st.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
String fm=fma.getText().toString();
String s=st.getText().toString();
Intent m = new Intent(getApplicationContext(), InActivity.class);
m.putExtra("f", fm);
m.putExtra("s", s);
startActivity(m);
}
});
}
});
}
else
{
Toast.makeText(getApplicationContext(),"Empty", Toast.LENGTH_LONG).show();
finish();
Intent menu = new Intent(getApplicationContext(), MenActivity.class);
menu.putExtra("username", dest);
startActivity(menu);
}
}
public void populateData() throws JSONException
{
resultVector = new Vector<ListDataItemInbox>();
int len = json_user.length();
System.out.println("length--------------------->"+len);
for(int i=0;i<len;i++)
{
JSONObject obj=json_user.getJSONObject(i);
listData = new ListDataItemInbox();
listData.sets(obj.getString(KEY_S));
listData.setd(obj.getString(KEY_D));
resultVector.add(listData);
myHandler.post(myRunnable);
}
}
private Handler myHandler = new Handler();
private Runnable myRunnable = new Runnable()
{
public void run()
{
customListAdapter = new ListViewAdapterInbox(InActivity.this);
customListAdapter.setResultsData(resultVector);
downloadList1.setAdapter(customListAdapter);
}
};
You can do something like this.
make the ArrayList in list adapter class
ArrayList<Integer> selectedIds = new ArrayList<Integer>();
and create this method also in that same class.
public void toggleSelected(Integer position){
selectedIds.clear();
selectedIds.add(position);
}
Now whenever you click on any item of listview pass that item position to this method. And inside your getView method set the check before setting the text. something like this..
if (selectedIds.contains(position)){
----- your code ----
}else{
----- your code ----
}
it perform the operation only on selected position . Try it.!
I need to create a number of check boxes programmatically using Java, check if one of them is checked and when I click Next Button the control will move to next page. If none of them is checked a toast message has to be displayed. Please suggest as I am new to Android.
Here is my code:
public class TestValidCheckboxActivity extends Activity implements OnCheckedChangeListener{
private RelativeLayout layoutMiddle = null;
private TableLayout layout1;
private CheckBox chk;
private String[] resarr = {"silu", "pinky", "meera"};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layoutMiddle = (RelativeLayout)findViewById(R.id.layoutMiddleUp);
layout1 = (TableLayout)findViewById(R.id.tableId1);
final Button btnNext = (Button)findViewById(R.id.btnNext);
int i = 0;
for(String res: resarr){
TableRow tr=new TableRow(this);
chk=new CheckBox(this);
chk.setId(i);
chk.setText(res);
chk.setTextColor(Color.BLACK);
tr.addView(chk);
i++;
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
lay.addRule(RelativeLayout.BELOW, layoutMiddle.getId());
layout1.addView(tr, lay);
}
chk.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if (arg1)
{
btnNext.setOnClickListener(new View.OnClickListener() {
public void onClick(final View view) {
Log.e("1111111111","111111111");
if(chk.isChecked()){
Intent intent = new Intent(view.getContext(),NextPage.class);
startActivityForResult(intent, 0);
}else{
Toast msg = Toast.makeText(view.getContext(), "please choose at least one option", Toast.LENGTH_LONG);
msg.show();
}
}
});
}else{
Toast msg = Toast.makeText(TestValidCheckboxActivity.this, "please choose at least one option", Toast.LENGTH_LONG);
}
}
});
}
#Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
}
}
this can be easily done
take a boolean flag and set true it on checkbox.isChecked();(inbuilt)
then check if flag is set then navigate to next else TOAST
Can you show us some of your layout code, meaning, are the checkboxes defined in an xml file and do they have IDs?
If they do, you can access each of them with findViewByID and check their status one by one.