hi i'm from Indonesia. sorry for my bad english language. i have
problem like this.

http://a7.sphotos.ak.fbcdn.net/hphotos-ak-ash4/261955_1871129290585_1011704401_31662629_977717_n.jpg

from the picture above if we select the radiobutton Pria and click
Save, then his name appears on the tab Pria. and we select the
radiobutton Wanita and click Save, then his name appears on the tab
Wanita. thanks before ..

my code
database2.java

public class database2 extends TabActivity {
    Cursor model=null;
    AlmagAdapter adapter=null;
    EditText nama=null;
    EditText alamat=null;
    EditText hp=null;
    RadioGroup jekel=null;
    AlmagHelper helper=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        helper=new AlmagHelper(this);

        nama=(EditText)findViewById(R.id.nama);
        alamat=(EditText)findViewById(R.id.alamat);
        hp=(EditText)findViewById(R.id.hp);
        jekel=(RadioGroup)findViewById(R.id.jekel);

        Button save=(Button)findViewById(R.id.save);

        save.setOnClickListener(onSave);

        ListView list=(ListView)findViewById(R.id.almag);


        model=helper.getAll();
        startManagingCursor(model);
        adapter=new AlmagAdapter(model);
        list.setAdapter(adapter);

        TabHost.TabSpec spec=getTabHost().newTabSpec("tag1");

        spec.setContent(R.id.almag);
        spec.setIndicator("Pria",
getResources().getDrawable(R.drawable.pria));
        getTabHost().addTab(spec);


        spec=getTabHost().newTabSpec("tag2");
        spec.setContent(R.id.lwanita);
        spec.setIndicator("Wanita",
getResources().getDrawable(R.drawable.perempuan));
        getTabHost().addTab(spec);


        spec=getTabHost().newTabSpec("tag3");
        spec.setContent(R.id.details);
        spec.setIndicator("Details",
getResources().getDrawable(R.drawable.alamat));

        getTabHost().addTab(spec);

        getTabHost().setCurrentTab(0);

        list.setOnItemClickListener(onListClick);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        helper.close();
    }

    private View.OnClickListener onSave=new View.OnClickListener() {
        public void onClick(View v) {
            String type=null;

            switch (jekel.getCheckedRadioButtonId()) {
                case R.id.pria:
                    type="Pria";

                    break;
                case R.id.perempuan:
                    type="Perempuan";
                    break;
            }

 
helper.insert(nama.getText().toString(),alamat.getText().toString(),type,hp.getText().toString());
            model.requery();
        }
    };

    private AdapterView.OnItemClickListener onListClick=new
AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent,
                                                            View view,
int position,
                                                            long id)
{
            model.moveToPosition(position);
            nama.setText(helper.getNama(model));
            alamat.setText(helper.getAlamat(model));
            hp.setText(helper.getHp(model));

            if (helper.getJekel(model).equals("Pria")) {
                jekel.check(R.id.pria);
            }
            else if (helper.getJekel(model).equals("Perempuan")) {
                jekel.check(R.id.perempuan);
            }


            getTabHost().setCurrentTab(1);
        }
    };

    class AlmagAdapter extends CursorAdapter {
        AlmagAdapter(Cursor c) {
            super(database2.this, c);
        }

        @Override
        public void bindView(View row, Context ctxt,
                                                 Cursor c) {
            AlmagHolder holder=(AlmagHolder)row.getTag();

            holder.populateFrom(c, helper);
        }

        @Override
        public View newView(Context ctxt, Cursor c,
                                                 ViewGroup parent) {
            LayoutInflater inflater=getLayoutInflater();
            View row=inflater.inflate(R.layout.row, parent, false);
            AlmagHolder holder=new AlmagHolder(row);

            row.setTag(holder);

            return(row);
        }
    }

    static class AlmagHolder {
        private TextView nama=null;
        private TextView alamat=null;
        private ImageView icon=null;
        private View row=null;

        AlmagHolder(View row) {
            this.row=row;

            nama=(TextView)row.findViewById(R.id.title);
            alamat=(TextView)row.findViewById(R.id.alamat);
            icon=(ImageView)row.findViewById(R.id.icon);
        }

        void populateFrom(Cursor c, AlmagHelper helper) {
            nama.setText(helper.getNama(c));
            alamat.setText(helper.getAlamat(c));

            if (helper.getJekel(c).equals("Pria")) {
                icon.setImageResource(R.drawable.pria);
            }
            else if (helper.getJekel(c).equals("Perempuan")) {
                icon.setImageResource(R.drawable.perempuan);
            }

        }
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        />
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                >
                <ListView android:id="@+id/almag"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                />
                <ListView android:id="@+id/lwanita"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                />
                <ListView android:id="@+id/lwanita"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"/>
            </LinearLayout>
            <TableLayout android:id="@+id/details"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:paddingTop="4px"
                >
                <TableRow>
                    <TextView android:text="Nama:" />
                    <EditText android:id="@+id/nama" />
                </TableRow>
                <TableRow>
                    <TextView android:text="Alamat:" />
                    <EditText android:id="@+id/alamat" />
                </TableRow>
                <TableRow>
                    <TextView android:text="Jekel:" />
                    <RadioGroup android:id="@+id/jekel">
                        <RadioButton android:id="@+id/pria"
                            android:text="Pria"
                        />
                        <RadioButton android:id="@+id/perempuan"
                            android:text="Perempuan"
                        />
                    </RadioGroup>
                </TableRow>
                <TableRow>
                    <TextView android:text="Hp:" />
                    <EditText android:id="@+id/hp"
                        android:gravity="top"
                        android:scrollHorizontally="false"

                    />
                </TableRow>
                <Button android:id="@+id/save"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Save"
                />
            </TableLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to