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.

ClassCastException fragments.MainActivity must implement OnHeadlineSelectedListener


AD MOB

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


397LW NO topic_id




AD

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


5

Random number Java | random-number-java


Generate random number Android Java example source code.

		Random rand = new Random();
		int i = rand.nextInt() % 256; // range -255  +255
		System.out.print(i + "

"); // -184 i = Math.abs(rand.nextInt() % 12); // range 0 +11 System.out.print(i); // 7



// Math.random() start with 0.  e.g. 0.35981234 
int nRan = (int) (Math.random()*10); // 0 - 10

// nextDouble(), nextFloat(), nextInt(), nextLong() returns 0 - 10
import java.util.Random;´

Random r = new Random();
int nRan = r.nextInt(); // 0 - 10
double dRan = r.nextDouble() * 10; // e.g. 7.496285271597397

nextDouble – return 0 - 1
nextFloat – same as double
nextInt –  -2147483648  +2147483647
nextLong –  -922337203685775808  +9223372036854775807
nextGaussian –  0.0 aberation 1.0.
321

Installation error: INSTALL_FAILED_CONTAINER_ERROR | installation-error-install_failed_container_error


1.) Try delete some apps from Android emulator (can from Eclipse DDMS perspective
- File Explorer tab - data/apps folder path )
2.) Try resize emulator internal storage or SD card storage to hight size
3.)Try add to AndroidManifest.xml android:installLocation="preferExternal"

<manifest xmlns:android="//schemas.android.com/apk/res/android"
    package="com.myweb.mypackage"
    android:installLocation="preferExternal"

4.) Try resize particion from Eclipse
Preferences,
select Android- Launch
Add "-partition-size 1024" into "Default emulator option” field.
Click "Apply” and use your emulator as usual
333

SimpleCursorAdapter deprecated | simplecursoradapter-deprecated


Constructor SimpleCursorAdapter is deprecated.
If using api 11 and above, you can try add last parameter 0.


Cursor cursor = managedQuery(...........,,,,);
// Specify the columns we want to display in the result
            String[] from = new String[] { KEY_WORD,
                                           KEY_DEFINITION };

            // Specify the corresponding layout elements where we want the columns to go
            int[] to = new int[] { R.id.word,
                                   R.id.definition };
// deprecated 
 SimpleCursorAdapter words =
            new SimpleCursorAdapter(this,
                    R.layout.result, cursor, from, to);
// working
 SimpleCursorAdapter words =
            new SimpleCursorAdapter(this,
                    R.layout.result, cursor, from, to, 0); // to, 0!!!!


//working in Fragment
SimpleCursorAdapter  mAdapter = new SimpleCursorAdapter(getActivity(),
                android.R.layout.simple_list_item_2, null,
                new String[] { "name", "age" }, // cursor parameters
                new int[] { android.R.id.text1, android.R.id.text2 }, 0);


140

Create Bitmap with Linear Gradient Android example | create-bitmap-with-linear-gradient-android-example



public class ApokusActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.GREEN);
            
            Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
             paint.setColor(Color.BLUE);
            
            Shader mShader = new LinearGradient(0, 0, 100, 70, new int[] {
                    Color.RED, Color.GREEN, Color.BLUE },
                    null, Shader.TileMode.MIRROR);  // CLAMP MIRROR REPEAT
            Canvas c = new Canvas(b);
            paint.setShader(mShader);
            //c.drawCircle(60, 60, 30, paint);
            c.drawRect(0, 0, 200, 200, paint);
            canvas.drawBitmap(b, 10,10, paint);
		}

	}
}


linear gradient bitmap android example
154

Create own custom Title Bar TitleBar with a Icon Android example | create-own-custom-title-titlebar-android-example


onCreate in MainActivity.java

    @Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main.xml);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
}


You can add to titlebar different Views by xml file.
custom_title.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android" android:id="@+id/screen"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView android:id="@+id/left_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Some text" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
       
        android:src="@drawable/ic_launcher" />
    
</RelativeLayout>





custom-title-titlebar-android


Editace: 2016-04-01 12:06:43
Počet článků v kategorii: 397
Url:classcastexception-fragments-mainactivity-must-implement-onheadlineselectedlistener

AD
11 Share
Share
Tweet