Array copy to Array Java Android example
String[] source = {"Hello","world","by","Android"};
String[] destination = new String[source.length];
System.arraycopy(source, 0, destination, 0, source.length);
396LW NO topic_id
AD
Další témata ....(Topics)
android:background="@android:color/transparent"
<LinearLayout
android:baselineAligned="false"
android:background="@android:color/transparent"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout>
////////////////////////////
LinearLayout mLinearLayout1 = (LinearLayout)findViewById(R.id.linearLayout1);
mLinearLayout1.setBackgroundColor(Color.TRANSPARENT);
Windows 7 64-bit version.
Eclipse 64-bit - Java was started but returned exit code=13
Solution:
Download and install 64-bit version of JDK
//www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Eclipse 64-bit - Java was started but returned exit code=13
Solution:
Download and install 64-bit version of JDK
//www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private Display mDisplay;
// onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get an instance of the SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
setContentView(R.layout.main); // main.xml or your xml file name
}
Map TreeMap key value pair, Map sort by key, Iterator for Map Java Android example.
MainClass.java
MainClass.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class MainClass {
public static void main(String[] arg) {
// english;germany dictionary
String[] arrayOfString = { "one;eine", "two;zwei", "three;drei", "four;vier" };
Map<String, String> map = new TreeMap<String, String>();
for(String s: arrayOfString){
String[] array = s.split(";");
String sKey ="", sValue="";
if(array.length > 1){
sKey = array[0]; sValue = array[1];
map.put(sKey, sValue);
}
}
List sortedByKeys=new ArrayList(map.keySet());
Collections.sort(sortedByKeys);
// iterate map
Set references = map.keySet();
Iterator it = references.iterator();
while (it.hasNext()) {
String key = (String) it.next();
String value = map.get(key);
System.out.println(key + " = " + value);
}
// or other example how iterate map
TreeSet<String> keys = new TreeSet<String>(map.keySet());
for (String key : keys) {
String value = map.get(key);
System.out.println(key + " = " + value);
}
// check if key exists
// if( map.containsKey("two")){
// System.out.print("two = " + map.get("two"));
// }
}
}
/*
four = vier
one = eine
three = drei
two = zwei
*/
// Context instead Activity as a parameter
@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
}
}
OnNoteClickedListener listener;
/* old emxample of usage
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (OnNoteClickedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnNoteClickedListener");
}
}
*/
// new version of code
@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
try {
listener = (OnNoteClickedListener) a;
} catch (ClassCastException e) {
throw new ClassCastException(a.toString()
+ " must implement OnNoteClickedListener");
}
}
}
Editace: 2011-11-20 11:05:23
Počet článků v kategorii: 396
Url:array-copy-to-array-java-android-example