آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

پاک کردن اطلاعات از جدول و نه از دیتابیس

mosafer  9 سال پیش  9 سال پیش
0 0

سلام

من یه tableLayout دارم که در هر سطرش یه کلید delete گذاشتم که همون سطر رو پاک میکنه..

ولی نمیخوام اون اطلاعات از دیتابیسم پاک بشن!

ینی وقتی کاربر کلید delete رو زد و اون سطر رو پاک کرد از دیتابیسم حذف نکنه و فقط از اون جدول پاک بشه.

ممنون میشم راهنمایی کنید....

0 0
میتونی اون رو از ارایه ای که از دیتابیس میخونه پاکش کنی. (9 سال پیش)
0 0
اگه میخوای هم دباره خونده نشه یه کلید تعریف کن تو دیتابیس و اون رو مثلا 0 کن موقعی که حذف رو کاربر میزنه تا دباره خونده نشه اما تو دیتا بیست حذف نمیشه. (9 سال پیش)
0 0
خب آقا مهدی من دقیق متوجه نشدم چی شد. خب چطور از آرایه باید پاکش کنم و اینکه این مطلب دومی که گفتین؟ (9 سال پیش)
0 0
@مهدی : منظورتون اینه که بگیم فقط اون row هایی رو مثلا بخونه که اون variable توی database ـشون 1 باشه . ( یعنی اونایی که 0 هست رو نخونه . ) درسته ؟ (9 سال پیش)
 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
mosafer  9 سال پیش
0 0

ببینید این کد منه که پایین کد من کلید delete گذاشتم..

  List<Match> listmatch = db.getMatch();
        //Toast.makeText(getApplicationContext(), "The number of registered Match = " + " ( " + String.valueOf(listmatch.size()) + " ) ", Toast.LENGTH_SHORT).show();
        Integer count = 0;
        for (final Match m: listmatch) {

            // Create the table row
            tr = new TableRow(this);
            int color;
            if (count % 2 != 0) {
                tr.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent));
                color = Color.WHITE;
            }
            else {
                tr.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));
                color = Color.WHITE;
            }
            tr.setId(m.Id);
            tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            //Create two columns to add as table data
            // Create a TextView to add date

            if (boolSetRow == true) {

                tr.setBackgroundDrawable(getResources().getDrawable(R.drawable.green_background));

            }
            else {

                TextView season = new TextView(this);
                season.setId(m.Id + 1);// define id that must be unique
                season.setText(m.Season); // set the text for the header 
                season.setTextColor(color); // set the color
                season.setPadding(5, 5, 5, 5);
                season.setGravity(Gravity.CENTER);
                season.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));

                // set the padding (if required)
                tr.addView(season); // add the column to the table row here

                TextView host = new TextView(this);
                host.setId(m.Id + 2);// define id that must be unique
                host.setText(m.Host); // set the text for the header 
                host.setTextColor(color); // set the color
                host.setPadding(5, 5, 5, 5);
                host.setGravity(Gravity.CENTER);
                host.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));

                // set the padding (if required)
                tr.addView(host); // add the column to the table row here

                TextView geust = new TextView(this);
                geust.setId(m.Id + 3);// define id that must be unique
                geust.setText(m.Guest); // set the text for the header 
                geust.setTextColor(color); // set the color
                geust.setPadding(5, 5, 5, 5);
                geust.setGravity(Gravity.CENTER);
                geust.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));

                // set the padding (if required)
                tr.addView(geust); // add the column to the table row here

                TextView Leg = new TextView(this);
                Leg.setId(m.Id + 4);// define id that must be unique
                Leg.setText(m.Leg); // set the text for the header 
                Leg.setTextColor(color); // set the color
                Leg.setPadding(5, 5, 5, 5);
                Leg.setGravity(Gravity.CENTER);
                Leg.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));

                // set the padding (if required)
                tr.addView(Leg); // add the column to the table row here

                TextView date = new TextView(this);
                date.setId(m.Id + 5);// define id that must be unique
                date.setText(m.Date); // set the text for the header 
                date.setTextColor(color); // set the color
                date.setPadding(5, 5, 5, 5);
                date.setGravity(Gravity.CENTER);
                date.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));

                // set the padding (if required)
                tr.addView(date); // add the column to the table row here

                TextView week = new TextView(this);
                week.setId(m.Id + 6);// define id that must be unique
                week.setText(m.Week); // set the text for the header 
                week.setTextColor(color); // set the color
                week.setPadding(5, 5, 5, 5);
                week.setGravity(Gravity.CENTER);
                week.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));

                // set the padding (if required)
                tr.addView(week); // add the column to the table row here

                TextView system = new TextView(this);
                system.setId(m.Id + 7);// define id that must be unique
                system.setText(m.System); // set the text for the header 
                system.setTextColor(color); // set the color
                system.setPadding(5, 5, 5, 5);
                system.setTextSize(12);
                system.setGravity(Gravity.CENTER);
                system.setBackgroundDrawable(getResources().getDrawable(R.drawable.transparent_footsall));
                // set the padding (if required)
                tr.addView(system); // add the column to the table row here

                Button Delete = new Button(this);
                Delete.setId(8);// define id that must be unique
                Delete.setText("Delete"); // set the text for the header 
                Delete.setTextColor(Color.WHITE);
                Delete.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_sabz));// set the color
                Delete.setPadding(5, 5, 5, 5);
                Delete.setGravity(Gravity.CENTER);
                // ownTeam.setBackgroundDrawable(getResources().getDrawable(R.drawable.border));
                // set the padding (if required)
                tr.addView(Delete); // add the column to the table row here

                Delete.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        final Dialog dialog = new Dialog(ActivityHomeMain.this);

                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
                        dialog.setContentView(R.layout.dialog_exit);
                        TextView txt = (TextView) dialog.findViewById(R.id.textView_dialog_exit);
                        txt.setText("Are you sure you want to delete this match?");

                        Button btn_ok = (Button) dialog.findViewById(R.id.btn_ok_dialog);

                        btn_ok.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View arg0) {

                                tableLayout_match.removeView(tr);
                                tableLayout_match.invalidate();

                                int id = tr.getId();

                                boolean result = db.deleteMatch(id);

                                if (result == true) {

                                    Log.i("onStart :", "delete");

                                }
                                else
                                {
                                    Log.i("onStart :", "Nodelete");
                                }

                                dialog.dismiss();

                            }
                        });

                        Button btn_no = (Button) dialog.findViewById(R.id.btn_no_dialog);
                        btn_no.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View arg0) {

                                dialog.dismiss();

                            }
                        });

                        dialog.show();
                    }
                });

 


پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .