‏إظهار الرسائل ذات التسميات Android. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات Android. إظهار كافة الرسائل

الأحد، 5 يناير 2014

Deleting Calendar event on Android

I have implemented android Calendar events with reference to this question - How to add calendar events in Android?

Below is the code I have used to add a new event to the Calendar

public void onClick(View v) { // TODO Auto-generated method stub String date = etMyTextB.getText().toString(); String time = "9:00 am"; SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); try { Date dt = df.parse(date + " " + time); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.clear(); cal.setTime(dt); Intent calIntent = new Intent(Intent.ACTION_EDIT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra("beginTime", cal.getTimeInMillis()); calIntent.putExtra("allDay", true); calIntent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000); calIntent.putExtra("title", "Revenue Licence Renewal Date"); startActivity(calIntent); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }}

I haven't used Content Providers because I need support for Android 2.x.x. My question is how can I Programmitically delete the event which have added using the above code?


View the original article here

الثلاثاء، 31 ديسمبر 2013

Android: Searchview searches only whole words

Search is based on starting characters, but i would like that will search everything. Here is part of my code, method onTextChanged isn't right, I think.. Thanks for help!

@Overridepublic void onCreate(Bundle savedInstanceState) { final ArrayList seznamPojmov = (ArrayList) SeznamPojmovRazlag(0); final ArrayList array_sort= new ArrayList(); super.onCreate(savedInstanceState); setContentView(R.layout.activity_slovar); final ListView list = (ListView) findViewById(R.id.slovar); final EditText iskanje = (EditText) findViewById(R.id.iskanje); final ArrayAdapter a = new ArrayAdapter (Slovar.this, android.R.layout.simple_list_item_1, array_sort)); } });

View the original article here

الخميس، 26 ديسمبر 2013

Any way to avoid "android:" statements in Android XML layout file?

Is there any way to avoid hundreds of "android:" statements in an Android XML layout file? I am new to Android and I find the "android:" statements make layouts very hard to read. Plus they are a pain to constantly type.

For example, instead of this:

android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_column="2"

I would like to just see this:

layout_width="wrap_content"layout_height="wrap_content"layout_column="2"

View the original article here

الثلاثاء، 24 ديسمبر 2013

What is the best way to do long running task in android?

I am new to android application development. I understand that in android, long running operations should not happen in main thread and we can use Async Task for doing the same. To do the following operations,

Download a file (> 5 MM) from server.Make a http/s call from the application.Make any call other than http (example - voice call) from the application.

is Async Task the best approach or do we have any other options in android for any of the above tasks?


View the original article here

Android - Background extending instead of aligning while scrolling

I'm trying to create a chat view(sent text,received text). The background drawable(box) is properly aligned to one side. When i scroll, it extends the box to fit the whole width. Not sure why this is happening. Any ideas? The problem i'm talking aboutHow i actually want it(this is before scrolling)

My custom adapter class

public class DisplayMessageAdapter extends ArrayAdapter {Context context;int sentResource, rcvdResource;ArrayList messages = null;public DisplayMessageAdapter(Context context, int sentResource, int rcvdResource, ArrayList messages) { super(context, sentResource, rcvdResource, messages); this.context = context; this.sentResource = sentResource; this.rcvdResource = rcvdResource; this.messages = messages;}@SuppressLint("NewApi")@Overridepublic View getView(int position, View convertView, ViewGroup parent) {View row = convertView;Message message = messages.get(position);Holder holder = new Holder(); if(row == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); holder = new Holder(); row = inflater.inflate(R.layout.message_layout, parent, false); holder.content = (TextView) row.findViewById(R.id.message_content); row.setTag(holder); } else { holder = (Holder) row.getTag(); } if(message.sent != null) { RelativeLayout.LayoutParams params = (LayoutParams) holder.content.getLayoutParams(); params.setMargins(30, params.topMargin, params.rightMargin, params.bottomMargin); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); holder.content.setLayoutParams(params); holder.content.setBackgroundResource(R.drawable.sent); holder.content.setText(message.sent); } else { RelativeLayout.LayoutParams params = (LayoutParams) holder.content.getLayoutParams(); params.setMargins(params.leftMargin, params.topMargin, 30, params.bottomMargin); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); holder.content.setLayoutParams(params); holder.content.setBackgroundResource(R.drawable.rcvd); holder.content.setText(message.received); }return row;}

My Layout file

My Drawables - rcvd/send


View the original article here

Can android apk file read and write xml file and update sqllite via xml data from server?

My problem is : 1) I want apk file to read xml file from remote server 2) Once its completed, I want to enter that data into sqllite db and process it. 3) Export updated data into xml format to remote server 4) Is apk file not able to update/read data from server?


View the original article here

الجمعة، 20 ديسمبر 2013

java.lang.IllegalStateException: Cannot add header view to list Android

i have one issues in my application , am setting header view to listview dynamically but am getting below error, i have two activies , A and B according my codition am setting header view to listview when am setting hederview in A activity it work fine but when A activity false my codition and go to B activity there am my contion is ture then come to A activity i neeed to add header view there am getting Error................ i have tryied to added onStart(), onResume() methods, but still am getting same error..... how to fix it

Java code

if (mDrawerList.getHeaderViewsCount()<1) { TextView headerText = new TextView(mContext); headerText.setGravity(Gravity.CENTER); headerText.setTextColor(getResources().getColor(R.color.white_color)); headerText.setPadding(20, 12, 20, 12); headerText.setTextSize(18); headerText.setText(mSessionManager.getUserName()); mDrawerList.addHeaderView(headerText); }

Error message

2-20 15:15:34.799: E/AndroidRuntime(13111): FATAL EXCEPTION: main12-20 15:15:34.799: E/AndroidRuntime(13111): java.lang.RuntimeException: Unable to resume activity {com.examle.EventListActivity}: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790)12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)12-20 15:15:34.799: E/AndroidRuntime(13111): at android.os.Handler.dispatchMessage(Handler.java:99)12-20 15:15:34.799: E/AndroidRuntime(13111): at android.os.Looper.loop(Looper.java:137)12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread.main(ActivityThread.java:5103)12-20 15:15:34.799: E/AndroidRuntime(13111): at java.lang.reflect.Method.invokeNative(Native Method)12-20 15:15:34.799: E/AndroidRuntime(13111): at java.lang.reflect.Method.invoke(Method.java:525)12-20 15:15:34.799: E/AndroidRuntime(13111): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)12-20 15:15:34.799: E/AndroidRuntime(13111): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)12-20 15:15:34.799: E/AndroidRuntime(13111): at dalvik.system.NativeStart.main(Native Method)12-20 15:15:34.799: E/AndroidRuntime(13111): Caused by: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.12-20 15:15:34.799: E/AndroidRuntime(13111): at android.widget.ListView.addHeaderView(ListView.java:258)12-20 15:15:34.799: E/AndroidRuntime(13111): at android.widget.ListView.addHeaderView(ListView.java:287)

View the original article here

Getting value from dynamic table in Android

This was my code for creating table and appending the data dynamically

table = (TableLayout)findViewById(R.id.table); inflater = getLayoutInflater(); for(int i = 0; i < 5; i++) { row = (TableRow)inflater.inflate(R.layout.row,table, false); TextView text = (TextView)row.findViewById(R.id.text1); text.setText("sss:" + i); text1 = (EditText)row.findViewById(R.id.text2); `enter code here` text2 = (TextView)row.findViewById(R.id.text3); text2.setText(""); text1.addTextChangedListener(new MyWatcher(text2)); table.addView(row); }

this code is working fine but my problem is when i click the button i want to get the values from each row which is to be only filledenter code here

NxtBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { } });

please help me out in this.


View the original article here

Fix camera capture to portrait on Android

I'm developing a small camera capture program in android.

I didn't use the Intent to open the camera and show it's images. I'm using the camera directly:

if (myPreviewRunning) { myCamera.stopPreview(); myPreviewRunning = false; } Camera.Parameters parameters = myCamera.getParameters(); display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); display = getWindowManager().getDefaultDisplay(); Camera.Size optimalSize = getOptimalSize(parameters.getSupportedPreviewSizes(), width, height); parameters.setPreviewSize(optimalSize.width, optimalSize.height); if (display.getRotation() == Surface.ROTATION_0 ||display.getRotation() == Surface.ROTATION_270) { parameters.setPreviewSize(optimalSize.height, optimalSize.width); ViewGroup.LayoutParams layoutParams = mySurfaceView.getLayoutParams(); layoutParams.width = optimalSize.height; layoutParams.height = optimalSize.width; mySurfaceView.setLayoutParams(layoutParams); myCamera.setDisplayOrientation(90); } else { myCamera.setDisplayOrientation(180); mySurfaceView.getLayoutParams().width = optimalSize.width; mySurfaceView.getLayoutParams().height = optimalSize.height; } myCamera.setParameters(parameters); myCamera.setPreviewDisplay(holder); myCamera.startPreview();

Until now, with this code I'm able to rotate the camera to a 'natural' behaviour, so when I rotate the cell phone to landscape, it rotates the image and you see it in landscape. But due to some reasons, I need the captured image to remain in portrait mode, even if I put landscape.

How can I force the camera preview to remain in portrait mode?

EDIT: AndroidManifest.xml


View the original article here