Berikut tampilan dari screenshotnya :
Berikut juga tampilan dari screenshoot yang nampak dari eclipse (dengan nama form_list_outlet.xml) :
Untuk source xml nya adalah sebagai berikut :
<?xml version="1.0" encoding="utf-8"?>yang diatas hanya untuk tampilan induk, sementara untuk list outlet nya sendiri tampilannya adalah sebagai berikut (pada eclipse dengan nama view_form_list_outlet.xml) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="USER NAME :"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="USER NAME"
android:inputType="text"
android:singleLine="true"
android:id="@+id/flo_user_name"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="NAMA OUTLET :"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="NAMA OUTLET"
android:inputType="text"
android:singleLine="true"
android:id="@+id/flo_nama_outlet"
/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/flo_list_outlet"
></ListView>
</LinearLayout>
Coding xml nya adalah :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Kode Outlet"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kode Outlet"
android:id="@+id/vlo_kode_outlet"
/>
</TableRow>
<TableRow >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Nama Outlet"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Outlet"
android:id="@+id/vlo_nama_outlet"
/>
</TableRow>
<TableRow >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Alamat Outlet"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alamat Outlet"
android:id="@+id/vlo_alamat_outlet"
/>
</TableRow>
<TableRow >
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Kota Outlet"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kota Outlet"
android:id="@+id/vlo_kota_outlet"
/>
</TableRow>
</TableLayout>
Terakhir untuk menyatukannya biar jalan buat file javanya dengan nama C_form_list_outlet_xtra.java Berikut codingnya :
package com.esa.demo;Sambung ke sini bro...
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
//import android.view.View.OnClickListener;
import android.widget.AdapterView;
//import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class C_form_list_outlet_xtra extends Activity{
mySqlHelper dbHelper;
protected Cursor cursor;
protected ListAdapter adapter;
String xuser_name;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.form_list_outlet);
Intent myIntent = this.getIntent();
final TextView flox_user_name = (TextView)
this.findViewById(R.id.flo_user_name);
final EditText flox_nama_outlet = (EditText)
this.findViewById(R.id.flo_nama_outlet);
flox_user_name.setText(myIntent.getStringExtra("xuser_name"));
flox_nama_outlet.setText("TEST");
flox_nama_outlet.setText("");
flox_nama_outlet.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
method_view_list_outlet_xtra();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
method_view_list_outlet_xtra();
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
method_view_list_outlet_xtra();
}
});
ListView flox_list_outlet = (ListView) findViewById(R.id.flo_list_outlet);
dbHelper = new mySqlHelper(this);
flox_list_outlet.setSelected(true);
flox_list_outlet.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2,
long arg3) {
// TODO Auto-generated method stub
AlertDialog.Builder ad=new AlertDialog.Builder(C_form_list_outlet_xtra.this);
ad.setTitle("Call");
ad.setMessage("Mulai CALL");
ad.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
method_view_list_outlet_xtra();
cursor.moveToPosition(arg2);
Intent myIntent =new Intent(C_form_list_outlet_xtra.this, C_cm_list_outlet.class);
myIntent.putExtra("xuser_name", flox_user_name.getText().toString());
myIntent.putExtra("xkode_outlet", cursor.getString(1).toString());
myIntent.putExtra("xnama_outlet", cursor.getString(2).toString());
myIntent.putExtra("xalamat_outlet", cursor.getString(3).toString());
myIntent.putExtra("xkota_outlet", cursor.getString(4).toString());
Calendar kini = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yy HH:mm");
//int jam = kini.get(Calendar.HOUR_OF_DAY);
insert_kunjungan(cursor.getString(1).toString(), df.format(kini.getTime()), flox_user_name.getText().toString());
startActivity(myIntent);
}
});
ad.show();
}
});
method_view_list_outlet_xtra();
}
public void method_view_list_outlet_xtra(){
EditText flox_nama_outlet = (EditText) this.findViewById(R.id.flo_nama_outlet);
ListView flox_list_outlet = (ListView) this.findViewById(R.id.flo_list_outlet);
SQLiteDatabase db = dbHelper.getReadableDatabase();
try{
cursor = db.rawQuery("SELECT * FROM t_outlet where nama_outlet like '%"+flox_nama_outlet.getText().toString()+"%' ORDER BY nama_outlet", null);
adapter = new SimpleCursorAdapter(
this,
R.layout.view_form_list_outlet,
cursor,
new String[] {"kode_outlet","nama_outlet","alamat_outlet","kota_outlet"},
new int[] {R.id.vlo_kode_outlet, R.id.vlo_nama_outlet, R.id.vlo_alamat_outlet, R.id.vlo_kota_outlet});
flox_list_outlet.setAdapter(adapter);}
catch(Exception e)
{
Log.e("error", e.toString());
}
}
public void insert_kunjungan (String kode_outlet, String kini, String user_name) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
try{
db.execSQL("INSERT INTO t_kunjungan(kode_outlet, masuk, user_name) VALUES('"+kode_outlet+"','"+kini+"','"+user_name+"')");
}catch(Exception e){
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
public boolean onCreateOptionsMenu(Menu menu){
menu.add(0,1,0,"Tambah Outlet");
menu.add(0,2,0,"Keluar");
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case 1:
tambah();
return true;
case 2:
finish();
return true;
}
return false;
}
public void tambah(){
TextView flox_user_name = (TextView) findViewById(R.id.flo_user_name);
Intent myIntent =new Intent(C_form_list_outlet_xtra.this, C_form_tambah_outlet.class);
myIntent.putExtra("xuser_name", flox_user_name.getText().toString());
startActivity(myIntent);
}
}
Yup, aplikasi siap di test... Anymore question... Tinggalkan komeng...
No comments:
Post a Comment