Skip to main content

Posts

Showing posts with the label assets

Load html file to WebView from assets in Android

Put the html file inside asset folder and use the code given below : public class MainActivity extends Activity { WebView myWebView; TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myWebView=(WebView) findViewById(R.id.webView1); myWebView.loadUrl("file:///android_asset/Noun.htm"); } Copy and download the code and try your self.

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...