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.

Every fragment must have an empty constructor Android Java Class


AD MOB

You have to add constructor!

    public static class YourFragment extends Fragment {
    //you have to add constructor!!!!!	
    public YourFragment(){}

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.activity_main, container, false);

            return view;
        }   

    }


397LW NO topic_id




AD

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


7

Show keyboard in WebView Android example | webview-keyboard


Show keyboard if WebView input have focus Android apps development example source code.

WebView webview;

//in onCreate

	webview = (WebView) findViewById(R.id.idWebviewPda);
	webview.getSettings().setJavaScriptEnabled(true);
	webview.loadUrl("//android.okhelp.cz");
	
	webview.requestFocus(View.FOCUS_DOWN);
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
            }
            return false;
        }
    });

173

Custom View Android Basic Example | custom-view-android-basic-example


Activity.java

public class A extends Activity{
	Bitmap bm;
	 TouchImageView touch;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.main);
		 
		 bm = BitmapFactory.decodeResource(getResources(), R.drawable.chinese_sky_map);
 		 touch =  (TouchImageView)findViewById(R.id.myImageView);
	  touch.setImageBitmap(bm);
		 
	}
}


\res\layout\main.xml


<?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:orientation="vertical" >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <cz.okhelp.TouchImageView.TouchImageView
        android:id="@+id/myImageView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        
        />

</LinearLayout>



location TouchImageView\src\cz\okhelp\TouchImageView\TouchImageView.java

public class TouchImageView extends ImageView {


    Context context;

// constructor wihtout using  *.xml file
//    public TouchImageView(Context context) {
//        super(context);
// }

// constructor with xml file
    public TouchImageView(Context context, AttributeSet attrs)
    {
      super(context, attrs);
      super.setClickable(true);
        this.context = context;
  }
}

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;
	}

}

371

FrameLayout fragment not visible Android | framelayout-fragment-not-visible-android


ListFragment show only one item issue

Try to change layout_width to 0dp

   <fragment android:name="cz.okhelp.android.fragchangfromlist.ArticleFragment"
              android:id="@+id/article_fragment"
              android:layout_weight="2"
              android:layout_width="0dp"
              android:layout_height="match_parent" />
<!--todo LAYOUT_WIDTH have to be 0dp !!!!!!!!!!!!!!!!!!!!! -->

    <FrameLayout android:id="@+id/article_fragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" />
214

LinkedMap HashMap Java | linkedmap-hashmap-java



Map<Float,String> linkedHashMap = new LinkedHashMap<Float, String>();

 linkedHashMap.put(14.f, "text");
 linkedHashMap.put(13.f, "text");
 linkedHashMap.put(10.f, "text");
 linkedHashMap.put(11.f, "text");
 linkedHashMap.put(2.f, "text");
 linkedHashMap.put(3.f, "text");
 linkedHashMap.put(1.f, "text");
 linkedHashMap.put(7.f, "text");
 linkedHashMap.put(23.f, "text");

	for (Entry<Float,String> entry : linkedHashMap.entrySet()) {
		System.out.println(entry.getKey());
	}
14.0
13.0
10.0
11.0
2.0
3.0
1.0
7.0
23.0

Map<Float,String> hashMap = new HashMap<Float, String>();

 hashMap.put(14.f, "text");
 hashMap.put(13.f, "text");
 hashMap.put(10.f, "text");
 hashMap.put(11.f, "text");
 hashMap.put(2.f, "text");
 hashMap.put(3.f, "text");
 hashMap.put(1.f, "text");
 hashMap.put(7.f, "text");
 hashMap.put(23.f, "text");

 
 
	for (Entry<Float,String> entry : hashMap.entrySet()) {
		System.out.println(entry.getKey());
	}
// key :
1.0
14.0
3.0
13.0
2.0
7.0
11.0
23.0
10.0




Editace: 2014-09-10 10:40:35
Počet článků v kategorii: 397
Url:every-fragment-must-have-an-empty-constructor-android-java-class

AD
11 Share
Share
Tweet