Get Resource ID by Resources String Name Android example
// image from res/drawable
int resID = getResources().getIdentifier("my_image",
"drawable", getPackageName());
// view
int resID = getResources().getIdentifier("my_resource",
"id", getPackageName());
// string
int resID = getResources().getIdentifier("my_string",
"string", getPackageName());
396LW NO topic_id
AD
Další témata ....(Topics)
HorizontalScrollView ScrollView LinearLayout horizontal vertical Android xml basic example and image.
[caption id="attachment_889" align="alignleft" width="200" caption="horizontal scrollview horizontalscrollview android"][/caption]
Other sample
[caption id="attachment_889" align="alignleft" width="200" caption="horizontal scrollview horizontalscrollview android"][/caption]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="//schemas.android.com/apk/res/android">
// horizontal and vertical Scrollview
<ScrollView android:id="@+id/ScrollView01"
android:layout_height="135px" android:layout_width="wrap_content"
android:scrollbars="horizontal|vertical">
// HorizontalScrollview
<HorizontalScrollView android:id="@+id/HorizontalScrollView01"
android:layout_height="fill_parent" android:layout_width="wrap_content">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:text="red" android:gravity="center_horizontal"
android:background="#aa0000" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="green" android:gravity="center_horizontal"
android:background="#00aa00" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="blue" android:gravity="center_horizontal"
android:background="#0000aa" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
<TextView android:text="yellow" android:gravity="center_horizontal"
android:background="#aaaa00" android:layout_width="200px"
android:layout_height="fill_parent" android:layout_weight="1" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<TextView android:text="row one" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:text="row two" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:text="row three" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:text="row four" android:textSize="15pt"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
Other sample
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello world! First TextView" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
How install Android emulator on PC
//developer.android.com/sdk/installing.html
Download links:
Java Development Kit JDK download
Eclipse download
Android SDK download
//developer.android.com/sdk/installing.html
Download links:
Java Development Kit JDK download
Eclipse download
Android SDK download
Eclipse.
If install on device signed with proguard *.apk package and try to reinstall it by only signed package get error in parsing the package.
Uninstall the first application with bigger size from device and try install signed package which has a smaller size. Delete from download list previous downloaded *.apk.
This problem occurs when that your downloaded apk file size is less than the
size of the original apk.
If install on device signed with proguard *.apk package and try to reinstall it by only signed package get error in parsing the package.
Uninstall the first application with bigger size from device and try install signed package which has a smaller size. Delete from download list previous downloaded *.apk.
This problem occurs when that your downloaded apk file size is less than the
size of the original apk.
Dialog Yes No sample code
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit application?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MyActivity.this.finish(); //Close this Activity for example: MyActivity.java
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// some code if you want
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
Update TextView from TimerTask, Handler, schedule, run, cancel TimerTask, Android example
public class TimerActivity extends Activity {
TimerTask mTimerTask;
final Handler handler = new Handler();
Timer t = new Timer();
TextView hTextView;
TableRow hTableRow;
Button hButton, hButtonStop;
private int nCounter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hTextView = (TextView)findViewById(R.id.idTextView);
hButton = (Button)findViewById(R.id.idButton);
hButton.setOnClickListener(mButtonStartListener);
hButtonStop = (Button)findViewById(R.id.idButtonStop);
hButtonStop.setOnClickListener(mButtonStopListener);
} // end onCreate
View.OnClickListener mButtonStartListener = new OnClickListener() {
public void onClick(View v) {
doTimerTask();
}
};
View.OnClickListener mButtonStopListener = new OnClickListener() {
public void onClick(View v) {
stopTask();
}
};
public void doTimerTask(){
mTimerTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
nCounter++;
// update TextView
hTextView.setText("Timer: " + nCounter);
Log.d("TIMER", "TimerTask run");
}
});
}};
// public void schedule (TimerTask task, long delay, long period)
t.schedule(mTimerTask, 500, 3000); //
}
public void stopTask(){
if(mTimerTask!=null){
hTextView.setText("Timer canceled: " + nCounter);
Log.d("TIMER", "timer canceled");
mTimerTask.cancel();
}
}
}
Editace: 2011-11-19 13:07:25
Počet článků v kategorii: 396
Url:get-resource-id-by-resources-string-name-android-example