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.

Convert Activity to Fragment Step by Step


AD MOB

public class Main extends Activity {

private TextView mTextView;
private Activity mAct;
private Intent mIntent;

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_layout);
  mTextView = findViewById(R.id.mTextView);
  mAct = getActivity();
  mIntent = getIntent();
 }

}


to:
public class Main extends Fragment{

 private TextView mTextView;
 private FragmentActivity mFrgAct;
 private Intent mIntent;
 private LinearLayout mLinearLayout;
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
          View root = inflater.inflate(R.layout.fragment_main, null);
        return root;
    }

 public void onViewCreated(View view, Bundle savedInstanceState) {
          // you can add listener of elements here
          /*Button mButton = (Button) view.findViewById(R.id.button);
            mButton.setOnClickListener(this); */
          mTextView = view.findViewById(R.id.mTextView);
          mLinearLayout = (LinearLayout)view;
 }
 public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
          mFrgAct = getActivity();
          mIntent = mFrgAct.getIntent(); //  Intent intent = new Intent(getActivity().getIntent());
 }

}




397LW NO topic_id




AD

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


66

Locale location Java Android example | locale-location-java-android-example



Locale lc = Locale.getDefault(); // default now locale on device
	String sCountry = lc.getCountry(); // CZ
	
	lc = new Locale("fr","FR"); //FRANCE .. Locale(language, country);
	String sCountry2 = lc.getDisplayCountry(); // Francie

	 Locale locale = Locale.GERMAN;					    
	 String sCountry3 = locale.getDisplayCountry(); // ""

 Locale locale = Locale.GERMAN;
 DateFormat formatter = new SimpleDateFormat("HH:mm:ss zzzz", locale);
 String s = formatter.format(new Date());//13:40:39 GMT+00:00					


// array of locales   
 Locale[] locales = { new Locale("fr", "FR"), new Locale("de", "DE"),
				        new Locale("en", "US") };


Locale locale = Locale.US;

// for date
DateFormat dateFormatterEurope = DateFormat.getDateInstance(DateFormat.DEFAULT,
					Locale.GERMANY);
Calendar myCalendar = Calendar.getInstance();
String sDate = dateFormatterEurope.format(myCalendar.getTime());

        final byte[] langBytes = locale.getLanguage().getBytes(Charsets.US_ASCII);
        
// UTF-8 most widely used text format for to properly display of text
        final Charset utfEncoding = Charsets.UTF_8;
        String text = "ěščřžýáíéůú"; 
        final byte[] textBytes = text.getBytes(utfEncoding);


// other Locale
CANADA
CANADA_FRENCH
CHINA
CHINESE
ENGLISH
FRANCE
FRENCH
GERMAN
GERMANY
ITALIAN
ITALY
JAPAN
JAPANESE
KOREA
KOREAN
PRC // Locale constant for zh_CN. 
ROOT // Locale constant for the root locale. 
SIMPLIFIED_CHINESE
TAIWAN
TRADITIONAL_CHINESE Locale constant for zh_TW. 
UK
US
112

How to capture screenshot of emulator window - Android sample | how-to-capture-screenshot-of-emulator-window-android-sample


When Eclipse and the emulator runs.
To access the DDMS perspective, go to Window > Open Perspective > DDMS. If DDMS does not appear, go to Window > Open Perspective > Other ... and select DDMS.

Open Devices TAB. Window -> Show view -> Devices

From Devices TAB select Screen Capture
Android emlator screen capture by eclipse
25

Copy sqlite database from apk package to device folder Android example | copy-sqlite-database-from-apk-to-device-folder-android-example


Put your sglite database to Android Eclipse project folder named Assets.
On device will copy database file to application folder as this example:



 public void createDatabase(Context myContext) throws IOException {
    String sPackName = myContext.getPackageName();
    InputStream assetsDB = myContext.getAssets().open("myDatabase");
    OutputStream dbOut = new FileOutputStream("/data/data/"+sPackName+"/database");
 
    byte[] buffer = new byte[1024];
    int length;
    while ((length = assetsDB.read(buffer))>0){
      dbOut.write(buffer, 0, length);
    }
 
    dbOut.flush();
    dbOut.close();
    assetsDB.close();
}


185

Get the color of a specific pixel Java Android example | get-the-color-of-a-specific-pixel-java-android-example



             ImputStream      is = this.getResources().openRawResource(R.drawable.colors);
             Bitmap    mBitmap2 = BitmapFactory.decodeStream(is);
        
         int  w = mBitmap2.getWidth();
         int  h = mBitmap2.getHeight();
//  int x , y have to be smaller as w , h 
         int _color =  mBitmap2.getPixel(x, y);

121

Android button text alignment left right - sample | android-button-textalignment


android:gravity="left|center_vertical" or android:gravity="right|center_vertical"
               
<Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="left|center_vertical"
                    android:paddingLeft="20dp"
                    android:text="My Button"
                     />



Editace: 2017-02-04 17:50:34
Počet článků v kategorii: 397
Url:convert-activity-to-fragment-step-by-step

AD
11 Share
Share
Tweet