Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Get package name Context-getPackageName Android example


AD MOB

If you often copy your Android project to another you have to using function for obtaining varied information about package.
This code show how get package name in Android application as string:

Context context = getContext(); // this.getContext(); getApplicationContext(); etc.
String sPackName = context.getPackageName();


397LW NO topic_id




AD

Další témata ....(Topics)


103

Android RadioGroup alignment like TableLayout | android-radiogroup-alignment-like-tablelayout


xml example source code with image.


   <TableLayout android:layout_width="match_parent" android:id="@+id/idTableInRadioGroup" android:layout_height="wrap_content">
        <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">


<RadioGroup android:id="@+id/idRadio_group_1_column"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:orientation="vertical">
 <RadioButton android:id="@+id/idRadio_1"
                android:text="@string/textLabel_1"/>
            <RadioButton android:id="@+id/idRadio_2"
                android:text="@string/textLabel_2"/>
            <RadioButton android:id="@+id/idRadio_3"
                android:text="@string/textLabel_3"/> 
 
        </RadioGroup>
<RadioGroup android:id="@+id/idRadio_group_2_column"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:orientation="vertical">
 
  <RadioButton android:id="@+id/idRadio_4"
                android:text="@string/textLabel_4"/>
            <RadioButton android:id="@+id/idRadio_5"
                android:text="@string/textLabel_5"/>
            <RadioButton android:id="@+id/idRadio_6"
                android:text="@string/textLabel_6"/>
        </RadioGroup>
</TableRow>        
    </TableLayout>



two-column-radiogroup-menu
298

SurfaceView implements Runnable Android Code | surfaceview-implements-runnable-android-code



package cz.okhelp.surfview;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;

public class MainActivity extends Activity implements OnTouchListener {
	OurView v;
	Bitmap ball, blob;
	float x, y;
	Sprite sprite;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.activity_our_view);
		v = new OurView(this);
		v.setOnTouchListener(this);
		ball = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
		x = y = 0;
		setContentView(v);
	}


	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		v.pause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		v.resume();
	}

	public class OurView extends SurfaceView implements Runnable {
		Thread t = null;
		SurfaceHolder holder;
		boolean isItOK = false;

		public OurView(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
			holder = getHolder();
		}

		public void run() {
			// TODO Auto-generated method stub
			while (isItOK == true) {
				// perform canvas drawing
				if (!holder.getSurface().isValid()) {
					continue;
				}
				// sprite = new Sprite(OurView.this,blob);
				Canvas c = holder.lockCanvas();
				c.drawARGB(255, 100, 100, 10);
				c.drawBitmap(ball, x, y, null);
				// onDraw(c);
				holder.unlockCanvasAndPost(c);
			}
		}

		protected void onDraw(Canvas canvas) {
			// sprite.onDraw(canvas);
		}

		public void pause() {
			isItOK = false;
			while (true) {
				try {
					t.join();
				} catch (InterruptedException e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				break;
			}// end while
		}

		public void resume() {
			isItOK = true;
			t = new Thread(this);
			t.start();
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			x = event.getX();
			y = event.getY();

			break;
		case MotionEvent.ACTION_UP:
			x = event.getX();
			y = event.getY();

			break;
		case MotionEvent.ACTION_MOVE:
			x = event.getX();
			y = event.getY();

			break;
		}// end switch

		return true;
	}

}

369

ClassCastException fragments.MainActivity must implement OnHeadlineSelectedListener | classcastexception-fragments-mainactivity-must-implement-onheadlineselectedlistener


Problem:
You have two class with similar names HeadLinesFragment and HeadMyLinesFragment with OnHeadlineSelectedListener.
Check if call correct class in MainActivity.
For example if use HeadMyLinesFragment change implement to HeadMyLinesFragment too!


public class MainActivity extends FragmentActivity 
        implements HeadLinesFragment.OnHeadlineSelectedListener { 
// wrong implements you need correct class name 
//implements  HeadMyLinesFragment.OnHeadlineSelectedListener
//............
HeadMyLinesFragment firstFragment = new HeadMyLinesFragment(); // because in code using HeadMyLinesFragment

21

How to install mount SD card for Eclipse Android Emulator | how-install-sd-card-on-android-eclipse-emulator


If you want download some *.apk file from internet and try on your emulator you get error than you have to install SD card. You have to closing Android emulator.
Mount Android emulator SD card instruction

  1. In Eclipse go in menu Window - Android SDK and Avg Manager

  2. Select Virtual devices

  3. Select AVD Name where you need install SD card

  4. Click on Edit button

  5. In open dialog go to SD card - Size: and write 500

  6. Press button Edit AVD

  7. Run AVD emulator


Image how install SD card on Android emulator in Eclipse.



255

Not request focus EditText if startup Android | not-request-focus-edittext-if-startup-android


Not request focus EditText if startup Android - hide keyboard if startup.

Remove: from EditText

Create a LinearLayout and set the:
attributes android:focusable="true" android:focusableInTouchMode="true"


   <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:orientation="vertical" >
</LinearLayout>


Editace: 2011-09-26 20:47:18
Počet článků v kategorii: 397
Url:get-package-name-context-getpackagename-android-example

AD
11 Share
Share
Tweet