Sunday, 29 November 2015

Cara Setting Value.Sring di Aplikasi Android

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">ContohEntriDatabase</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
      <string name="menu_settings">Settings</string>
    <string name="title_activity_main">Contoh Entri Database</string>
    <string name="barang_hint">Nama Barang</string>
    <string name="harga_barang">Harga Barang</string>
    <string name="merk_barang">Merk Barang</string>
    <string name="buttom_submit">buttom submit</string>
    <string name="tombol_tambah">Tambah Data</string>
    <string name="tombol_lihat">Lihat Data</string>
    <string name="tombol_setting">Setting</string>
    <string name="title_view">Data Barang</string>
    <string name="ex">Exit</string>
    <string name="create_data">Create Data</string>
    <string name="view_data">View</string>
    <string name="unused">unused</string>
    <string name="title_activity_setting">Setting</string>
    <string name="nama_barang">Nama Barang</string>

</resources>

Setting Konfigurasi Android Manifest pada Aplikasi Android

//*Author : midasoft.blogspot.com
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.contohentridatabase"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MainActivity" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity
            android:name=".CreateData"
            android:label="@string/title_activity_main" >
        </activity>
            
        <activity
            android:name=".ViewData"
            android:label="@string/title_activity_main" >
        </activity>
    </application>

</manifest>


Source code View Data XML di Android

//Author: midasoft.blogspot.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/data_view"
        android:layout_width="118dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/title_view" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.71" >
    </ListView>

</LinearLayout>

Source code cara membuat View Data.java dengan Aplikasi Android

package com.example.contohentridatabase;
//Author: midasoft.blogspot.com
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;

public class ViewData extends ListActivity {
       
    //inisialisasi kontroller    
      private DBDataSourceMob dataSource;
       
    //inisialisasi arraylist  
      private ArrayList<Barang> values;

      @Override
    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.viewdata);
 
          dataSource = new DBDataSourceMob(this);
          // buka kontroller         
          dataSource.open();
 
          // ambil semua data barang         
          values = dataSource.getAllBarang();
                       
                       
          // masukkan data barang ke array adapter      
          ArrayAdapter<Barang> adapter = new ArrayAdapter<Barang>(this,
         android.R.layout.simple_list_item_1, values);
              
          // set adapter pada list         
          setListAdapter(adapter);
    }

}

Source code Entri Data XML di Aplikasi Android

//Author: midasoft.blogspot.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/nama_barang"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:hint="@string/nama_barang"
        android:inputType="text" />

        <EditText
            android:id="@+id/merk_barang"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:ems="10"
            android:hint="@string/merk_barang"
            android:inputType="text" >
 
        <requestFocus />
    </EditText>

        <EditText
            android:id="@+id/harga_barang"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:ems="10"
            android:hint="@string/harga_barang"
            android:inputType="number" >
 
        <requestFocus />
    </EditText>
 
    <Button
        android:id="@+id/buttom_submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/buttom_submit"
        android:onClick="submit"
        android:text="Submit" />

</LinearLayout>