为什么我的listview重复显示屏幕而不是显示sqlite寄存器

时间:2014-08-07 12:22:23

标签: java android sqlite listview

我的listview有问题,我希望它显示来自sqlite的数据,但应用程序复制了屏幕

这是layout.xml

<?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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="182dp"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tVArea"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Area Code" />

            <EditText
                android:id="@+id/eTArea"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="text" />

            <TextView
                android:id="@+id/tVSupervisor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Worker Code" />

            <EditText
                android:id="@+id/eTSupervisor"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10" />

            <TextView
                android:id="@+id/tVdate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Date" />

            <EditText
                android:id="@+id/eTDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="date" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tVTrackRecord"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Track Record" />

            <EditText
                android:id="@+id/eTRegisterCode"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/bRegister"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="+" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ToggleButton
                android:id="@+id/TBBowl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <ToggleButton
                android:id="@+id/ToggleButton03"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ToggleButton" />

            <ToggleButton
                android:id="@+id/ToggleButton02"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ToggleButton" />

            <ToggleButton
                android:id="@+id/ToggleButton01"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ToggleButton" />

            <ToggleButton
                android:id="@+id/toggleButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ToggleButton" />
        </LinearLayout>

        <RelativeLayout
            android:id="@+id/RelativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tVPattern"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_weight="1"
                android:text="Pattern" />

            <EditText
                android:id="@+id/eTPattern"
                android:layout_width="71dp"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_below="@+id/tVPattern"
                android:layout_toLeftOf="@+id/eTColor"
                android:layout_weight="1"
                android:ems="10" />

            <TextView
                android:id="@+id/tVColor"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/eTColor"
                android:layout_alignParentTop="true"
                android:layout_weight="1"
                android:text="Color" />

            <TextView
                android:id="@+id/tVQuantity"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/eTQuantity"
                android:layout_alignLeft="@+id/eTQuantity"
                android:layout_weight="1"
                android:text="Quantity" />

            <EditText
                android:id="@+id/eTQuantity"
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/eTColor"
                android:layout_alignBottom="@+id/eTColor"
                android:layout_marginRight="26dp"
                android:layout_toLeftOf="@+id/bAddCount"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />

            <EditText
                android:id="@+id/eTColor"
                android:layout_width="68dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tVColor"
                android:layout_toLeftOf="@+id/tVQuantity"
                android:layout_weight="1"
                android:ems="10" />

            <Button
                android:id="@+id/bAddCount"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="19dp"
                android:layout_weight="1"
                android:text="+" />

        </RelativeLayout>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ListView
            android:id="@+id/listCount"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <TextView
            android:id="@+id/tVLRowCountID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RowCountID" />

        <TextView
            android:id="@+id/tVLRegisterCode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RegisterCode" />

        <TextView
            android:id="@+id/tVLCodePattern"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pattern" />

        <TextView
            android:id="@+id/tVLColor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Color" />

        <TextView
            android:id="@+id/tVLQuantity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </RelativeLayout>

</LinearLayout>

这是我阅读listview的数据库

    package com.example.productioncontrolinventory;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class InventoryDB {


    private static final String DATABASE_NAME = "inventory.db";


    public static final String DATABASE_TABLEACOUNT = "acount";
        public static final String KEY_ROWACOUNTYID = "_id";
        public static final String KEY_AREACODE = "code_area";
        public static final String KEY_DATEACOUNT = "date_acount";
        public static final String KEY_SUPERVISORCODE = "code_supervisor";
        public static final String KEY_REGISTERCODE = "code_register";
        public static final String KEY_PATTERNCODE = "code_pattern";
        public static final String KEY_COLORCODE = "code_color";
        public static final String KEY_QUANTITY = "quantity";

        private static final int DATABASE_VERSION  = 1;

        private DbHelper ourHelper;
        private final Context ourContext;
        private static SQLiteDatabase ourDatabase;


//___________________________________________________________________________________       
        public static class DbHelper extends SQLiteOpenHelper{

            public DbHelper(Context context) {
                        super(context, DATABASE_NAME, null, DATABASE_VERSION);
            }

            @Override
            public void onCreate(SQLiteDatabase db) {
                // Create Table Studies
                db.execSQL(" CREATE TABLE " + DATABASE_TABLEACOUNT + " (" +
                        KEY_ROWACOUNTYID + " INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, " +
                        KEY_AREACODE + " TEXT NOT NULL, " +
                        KEY_DATEACOUNT + " TEXT NOT NULL, " +
                        KEY_SUPERVISORCODE + " TEXT NOT NULL, " +
                        KEY_PATTERNCODE + " TEXT NOT NULL, " +
                        KEY_COLORCODE + " TEXT NOT NULL, " +
                        KEY_QUANTITY + " INTEGER NOT NULL, " +                      
                        KEY_REGISTERCODE + " INTEGER NOT NULL);"            
                );
            }
            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                db.execSQL(" DROP TABLE IF EXIST " + DATABASE_TABLEACOUNT);
                onCreate(db);
            }

        }

//___________________________________________________________________________________       
        public InventoryDB(Context c){
            ourContext = c;
        }
        public InventoryDB open(){
            ourHelper = new DbHelper(ourContext);
            ourDatabase = ourHelper.getWritableDatabase();
            return this;
        }
        public void close(){
            ourHelper.close();
        }
//___________________________________________________________________________________
        public long createEntryInventory(String eTRegisterCode,
                String eTPattern, String eTColor, String eTQuantity,
                String eTArea, String eTSupervisor, String eTDate) {
            // Insertar en la base de datos el registro nuevo
            ContentValues cv = new ContentValues();
            cv.put(KEY_REGISTERCODE, eTRegisterCode);
            cv.put(KEY_PATTERNCODE, eTPattern);
            cv.put(KEY_COLORCODE, eTColor);
            cv.put(KEY_QUANTITY, eTQuantity);
            cv.put(KEY_AREACODE, eTArea);
            cv.put(KEY_SUPERVISORCODE, eTSupervisor);
            cv.put(KEY_DATEACOUNT, eTDate);
            return ourDatabase.insert(DATABASE_TABLEACOUNT, null, cv);  
        }

        //ListView for Pieces Counted in a Register
        public static Cursor ListViewCount() {
            // TODO Auto-generated method stub
            Cursor mCursor = ourDatabase.query(DATABASE_TABLEACOUNT, 

                    new String[] {KEY_ROWACOUNTYID + " AS _id",
                    KEY_REGISTERCODE,
                    KEY_PATTERNCODE, 
                    KEY_COLORCODE,
                    KEY_QUANTITY},
                    null, null, null, null, null);

                  if (mCursor != null) {
                   mCursor.moveToFirst();
                  }
                  return mCursor;
        }

}

这是用于执行的java代码

    package com.example.productioncontrolinventory;

import com.example.productioncontrolinventory.Inputinventory;



import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class Inputinventory extends Activity implements OnClickListener{

    Button bRegister, bAddCount;
    EditText eTRegisterCode, eTPattern, eTColor, eTQuantity, eTArea, eTSupervisor, eTDate;
    private SimpleCursorAdapter dataAdapter;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.inputinventory);

        bRegister = (Button) findViewById(R.id.bRegister);
        bAddCount = (Button) findViewById(R.id.bAddCount);
        eTRegisterCode = (EditText) findViewById(R.id.eTRegisterCode);
        eTPattern = (EditText) findViewById(R.id.eTPattern);
        eTColor = (EditText) findViewById(R.id.eTColor);
        eTQuantity = (EditText) findViewById(R.id.eTQuantity);
        eTArea = (EditText) findViewById(R.id.eTArea);
        eTSupervisor = (EditText) findViewById(R.id.eTSupervisor);
        eTDate = (EditText) findViewById(R.id.eTDate);

        bRegister.setOnClickListener(this);
        bAddCount.setOnClickListener(this);

        //Initialize the predetermined fields
        //Blank Fields
        eTPattern.setText("");
        eTQuantity.setText("");
        eTArea.setText("");
        eTSupervisor.setText("");
        //By Default
        eTColor.setText("00");
        //eTDate = Today();
        //eTRegistrationCode;

        //View of Register Add
        InventoryDB info = new InventoryDB(this);
        info.open();
        displayViewCount();
        info.close();



    }

    private void displayViewCount() {
            // TODO Auto-generated method stub
            Cursor cursor = InventoryDB.ListViewCount();
            //startManagingCursor(cursor);
            String[] from = new String[] {
                    InventoryDB.KEY_ROWACOUNTYID,
                    InventoryDB.KEY_REGISTERCODE,
                    InventoryDB.KEY_PATTERNCODE,
                    InventoryDB.KEY_COLORCODE,
                    InventoryDB.KEY_QUANTITY,
                  };
            int[] to = new int[] {
                    R.id.tVLRowCountID,
                    R.id.tVLRegisterCode,
                    R.id.tVLCodePattern,
                    R.id.tVLColor,
                    R.id.tVLQuantity,
                  };
            dataAdapter = new SimpleCursorAdapter(this, R.layout.inputinventory, cursor, from, to, 0);
            ListView listView1 = (ListView) findViewById(R.id.listCount);
              // Assign adapter to ListView
              listView1.setAdapter(dataAdapter);
              registerForContextMenu(listView1);
        }

    public void onClick(View v) {
        switch(v.getId()){
            case R.id.bRegister:
                eTRegisterCode.setText("works");
            //Increase the counted paper

                break;
            case R.id.bAddCount:
            //Add the register
            String eT_RegisterCode = eTRegisterCode.getText().toString();
            String eT_Pattern = eTPattern.getText().toString();
            String eT_Color = eTColor.getText().toString();
            String eT_Quantity = eTQuantity.getText().toString();
            String eT_Area = eTArea.getText().toString();
            String eT_Supervisor = eTSupervisor.getText().toString();
            String eT_Date = eTDate.getText().toString();

            InventoryDB entry = new InventoryDB(Inputinventory.this);
            entry.open();
            entry.createEntryInventory(eT_RegisterCode,eT_Pattern,eT_Color,eT_Quantity,eT_Area,eT_Supervisor,eT_Date);
            entry.close();
            this.finish();
                //Reset a Values
                eTColor.setText("00");
                eTQuantity.setText("");

                break;
            }
    }

}

我在exectue

上传logcat

D / dalvikvm(1846):GC_FOR_ALLOC释放87K,5%释放3107K / 3260K,暂停147ms,总计151ms D / dalvikvm(1846):GC_FOR_ALLOC释放6K,5%自由3157K / 3316K,暂停204ms,总计306ms I / dalvikvm-heap(1846):将堆(frag case)增长到3.750MB,用于635808字节分配 D / dalvikvm(1846):GC_FOR_ALLOC释放<1K,5%游离3777K / 3940K,暂停269ms,总计269ms I / Choreographer(1846):跳过270帧!应用程序可能在其主线程上做了太多工作。 D / gralloc_goldfish(1846):未检测到GPU仿真的仿真器。 I / Choreographer(1846):跳过66帧!应用程序可能在其主线程上做了太多工作。 I / Choreographer(1846):跳过62帧!应用程序可能在其主线程上做了太多工作。

问题出在下一个:

如果您看到图片:http://tinypic.com/r/e9u4hw/8

您可以看到2个区域红色和黄色。 在黄色区域应该有一个带有sqlite寄存器的列表视图(表中包含几个参数),但是它们显示的是列表视图,其中显示的每个寄存器都是红色区域跟踪记录中设置的布局,工作人员代码,按钮(+)......

由于

1 个答案:

答案 0 :(得分:0)

目前还不清楚具体问题是什么。

但请注意,在RelativeLayout中,除非另有说明,否则默认情况下,孩子会在左上角布置,相互重叠。

要使RelativeLayout个孩子相对于彼此布局,请添加一些布局规则。例如,要获得与垂直LinearLayout类似的结果,请使用

android:layout_below="@id/id_of_previous_child_view"
RelativeLayout子视图中的

属性。