Skip to main content

Posts

Showing posts with the label display

Using DialogFragments in Android

MainActivity.java : public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); dialogfragment testDialog = new dialogfragment(); testDialog.setRetainInstance(true); testDialog.show(fm, "fragment_name"); }} Dialogfragment.java : public class Dialogfragment extends DialogFragment { public void TestDialog() { // Empty constructor required for DialogFragment } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View view = inflater.inflate(R.layout.dialog, container); return view; } } dialog.xml : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/edit_name" ...

ContextMenu in Android

Long click on the button to open the menu. in java class: public class ContextmenuActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b=(Button)findViewById(R.id.button1); registerForContextMenu(b); } //create the menuuu====================== @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater=getMenuInflater(); inflater.inflate(R.layout.contextmenu, menu); } //click to each menu====================== @Override public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub if(item.getItemId()==R.id.item1) ...

Custom AlertBox in Android

in main.xml file: < ?xml version="1.0" encoding="utf-8"?> < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > < Button android:id="@+id/button1" android:layout_width="120dp" android:layout_height="wrap_content" android:text="Button" /> < /LinearLayout> in dialog.xml :(xml for custom dialog box) : < ?xml version="1.0" encoding="utf-8"?> < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > < ImageView android:id="@+id/imageView1" android:layout_widt...

Read from Asset and Write to a TextView

Code for reading from a text file in asset folder to a textview: public class Readfile extends Activity { String path; ArrayList data = new ArrayList (); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); path = getResources().getString(R.string.directory1); String[] data1 = null; AssetManager am = getResources().getAssets(); try { data1 = am.list(path); } catch (Exception e) { } for (String name : data1) { data.add(name); } Readoperation(); } public void Readoperation() { // TODO Auto-generated method stub TextView txt = (TextView) findViewById(R.id.text); try { path=getResources().getString(R.string.directory1) +"/"+data.get(2); InputStream stream = getAssets().open(path); int size = stre...

Working with images in Corona

Loading an Image : syntax: display.newImage( filename [, baseDirectory] [, left, top] ) example: newImage = display.newImage( "image.png", 10, 20 ) myImage2 = display.newImage( "image.png" ) Image Autoscaling: The default behavior of display.newImage() is to auto-scale large images.To control manually we can use boolean value. syntax: display.newImage( [parentGroup,] filename [, baseDirectory] [, x, y] [,isFullResolution] ) example: newImage = display.newImage( "image.png", 10, 20, true ) Images with Dynamic Resolution : syntax: display.newImageRect( [parentGroup,] filename [, baseDirectory] w,h ) example: newImage = display.newImageRect( "Image.png", 100, 100 )