Android Features:
1: what is the difference b/w implicit intents and explicit intents?
Ans:
intent which has target component name( which we created our own Activity name) is explicit intent.
the intent which don't know target component name is known as a implicit intents
Important code:
Q: How to get system current date?
Ans:
//Get Current Date
Calendar c=Calendar.getInstance();
SimpleDateFormat dfm=new SimpleDateFormat("MM/dd/yyyy");
currentdate=dfm.format(c.getTime());
Q: how to set minimum date to Date Picker in android?
Ans:
public void dpd2()
{
Calendar c=Calendar.getInstance();
DatePickerDialog d=new DatePickerDialog(this, new OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
txtTo.setText((monthOfYear+1)+"/"+dayOfMonth+"/"+year);
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
String d1=txtFromDate.getText().toString();
StringTokenizer token1=new StringTokenizer(d1, "/");
//month
String s1=token1.nextToken();
//date
String s2=token1.nextToken();
//year
String s3=token1.nextToken();
Date date=new GregorianCalendar(Integer.parseInt((s3)),Integer.parseInt((s1))-1,Integer.parseInt((s2))).getTime();
long diff=date.getTime();
d.getDatePicker().setMinDate(diff);
d.show();
/*
d.getDatePicker().setMaxDate(System.currentTimeMillis());
d.show();*/
}
Q: Generate Random number in Android?
Ans: public static class RandomGenerator
{
private static Random random = new Random((new Date()).getTime());
public static String generateRandomString(int length)
{
char[] values = {'A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z','0','1','2','3',
'4','5','6','7','8','9'};
for (int i=0;i<5;i++)
{
int idx=random.nextInt(values.length);
out += values[idx];
}
return out;
}
}
Q1> what is the difference between dp and px?
ans: px=pixels, which means absollute value,
dp/dip= density indepandent pixels, this is alternative of px. if we use 'px' , ex: if we downloded the app for other resollution the size will not automatically streach.
we can overcome this with the help of 'dip/dp'.
Q2> getting last file name vlaue(2014_102822.jpg) from following String
String picturePath=storage/camera/internal/2014_102822.jpg
Ans:
String filename="";
StringTokenizer token1=new StringTokenizer(picturePath, "/");
while (token1.hasMoreElements())
{
filename=token1.nextToken();
}
Q3> for removing "java heap space error" in eclipse android?
--->Windows > Preferences > Java > Installed JREs
--->Check the JRE version you are using
--->Click “Edit” to open “Edit JRE” dialogue box
--->Now add “-Xms768m -Xmx1024m” argument to “Default VM Arguments”.
Q4> for specific keyboard in android?
--> Give this in strings.xml file as
<string name="myAlphaNumeric">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</string>
and add to edittext
android:digits="@string/myAlphaNumeric"
Q5> who founded Android?
Ans:
Android Inc was founded in Palo Alto of California, U.S. by Andy Rubin,Rich miner, Nick sears and Chris White in 2003. Later Android Inc. was acquired by Google in 2005.
Q6> Cntrl+ Space Not Working?
Ans:
For some reason Kepler changes the settings for Content Assist on Juno workspaces.
Checking the Java Proposals checkbox in Preferences -> Java\Editor\Content Assist\Advanced should resolve this problem.
Q7> What is the difference between activity and Fragment?
Ans:
A. fragment is a part of an activity, which contributes its own UI to that activity. Fragment can be thought like a sub activity.
Where as the complete screen with which user interacts is called as activity. An activity can contain multiple
fragments.Fragments are mostly a sub part of an activity.
B. An activity may contain 0 or multiple number of fragments based on the screen size. A fragment can be reused in multiple
activities, so it acts like a reusable component in activities.
C. A fragment can't exist independently. It should be always part of an activity. Where as activity can exist with out any fragment in it.
Q8> Make a phone call from fragment
Ans:
String phno=phn.getText().toString();
Intent callintent=new Intent(Intent.ACTION_CALL);
callintent.setData(Uri.parse("tel:"+phno));
startActivity(callintent);
-- And add this permission in manifest.xml
<uses-permission android:name="android.permission.CALL_PHONE"/>
Q9> Set max lenght to edttext
Ans:
txtPatientName.setFilters(new InputFilter[] { new InputFilter.LengthFilter(125) });
Q10> How to difference between two dates?
Ans:
public String validationfrom()
{
String msg="";
String dateStart = txtFromDate.getText().toString();
String dateStop =txtTo.getText().toString();
SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy");
Date d1=null;
Date d2=null;
long diffDays=0;
// String daysdiff = "";
try
{
d1 = sdf.parse(dateStart);
d2 = sdf.parse(dateStop);
long d=d2.getTime()-d1.getTime();
diffDays = d / (24 * 60 * 60 * 1000);
// String dif=""+diffDays;
}
catch (Exception e)
{
//Toast.makeText(getApplicationContext(),"catch", 2000).show();
}
if(diffDays>7)
{
msg=msg+"Select maximum Date for 7 Days Period";
}
if(txtFromDate.getText().toString().equalsIgnoreCase("") || txtTo.getText().toString().equalsIgnoreCase(""))
{
msg=msg+", Please select Dates";
}
/* if(txtFromDate.getText().toString().equalsIgnoreCase(""))
{
msg=msg+", From Date";
}
if(txtTo.getText().toString().equalsIgnoreCase(""))
{
msg=msg+", To field";
}*/
return msg;
}
Q11> How to underline text in android?
Ans:
btnshowmore.setPaintFlags(btnshowmore.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
Q12> How make specific text underline with bold and colored?
Ans: tvComments.setText(Html.fromHtml(": Risk High/<font color=\"#FF0000\"><b><u>update</u></b></font> your values"));
Q13> Date picker dialog main usable property?
Ans:
dpd.getDatePicker().findViewById(Resources.getSystem().getIdentifier("year", "id", "android")).setEnabled(false);
Q14> set dynamic height and widht to any component?
Ans:
lst_todo_System.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 20));
Q15> http://www.mayanklangalia.blogspot.in/search/label/facebook%20integration
Q16> how to set underline to text?
Ans:
btnshowmore.setPaintFlags(btnshowmore.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
Q17> How to Navigating from one app to another App?
Ans:
PackageManager pm = activity.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.example.healthkos");
startActivity(intent);
Q18> How to set dialog fragment background as Trasperent?
Ans:
Dailog d;
d.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Q19> How to find out date is in between two dates?
try{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date date1=sdf.parse("2010-12-05");
Date date2=sdf.parse("2010-12-15");
Date date3=sdf.parse("2010-12-07");
if(date3.compareTo(date1)>=0 && date3.compareTo(date2)<=0)
{
System.out.println("date is in between these dates...");
}
else
{
System.out.println("out of in between these days");
}
}
catch(Exception e)
{
}
No comments:
Post a Comment