Android 滚动视图,就像listview一样,从数据库设置textview

Android 滚动视图,就像listview一样,从数据库设置textview,android,database,cursor,textview,scrollview,Android,Database,Cursor,Textview,Scrollview,我正试图从一个列表视图转移到另一个活动中,其中一个活动的TextView和Edittext相邻。listview中的Edittext给我带来了很多麻烦,我试图使我的滚动视图看起来像listview,但没有任何回收问题。我已经设置了一个布局开始(不是100%我希望它看起来像什么),但现在我想用从数据库中提取的数据填充我的textview,我在这里碰到了一堵墙。这是我到目前为止所拥有的 public class inputpage extends Activity { public stat

我正试图从一个列表视图转移到另一个活动中,其中一个活动的TextView和Edittext相邻。listview中的Edittext给我带来了很多麻烦,我试图使我的滚动视图看起来像listview,但没有任何回收问题。我已经设置了一个布局开始(不是100%我希望它看起来像什么),但现在我想用从数据库中提取的数据填充我的textview,我在这里碰到了一堵墙。这是我到目前为止所拥有的

public class inputpage extends Activity {
    public static int editCount = 10; //needs to be dynamic based on how many items the cursor pulls but using 10 till I have more code in place 
    public LinearLayout editlayout;
    static Map<Integer, String> inputValues = new LinkedHashMap<Integer, String>();
    @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.inputlayout);
    editlayout=(LinearLayout) this.findViewById(R.id.editlayout);

    buildRow();



}

    public void buildRow(){
        LayoutParams textparam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        LayoutParams editparam = new LayoutParams(350, LayoutParams.WRAP_CONTENT);
        textparam.setMargins(2, 2, 2, 2);

        for (int i = 0; i < editCount; i++){
            //textview
            TextView tv=new TextView(this);
            tv.setLayoutParams(textparam);
            tv.setText("test");
            tv.setTextSize(35);
            tv.setTextColor(getResources().getColor(R.color.black));
            this.editlayout.addView(tv);
            //edittext
            EditText edit = new EditText(this);
            edit.setLayoutParams(editparam);
            this.editlayout.addView(edit);
            edit.setId(editCount);
            edit.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable editable) {
                Log.e(String.valueOf(editCount), "Position in array");
                inputValues.put(editCount, editable.toString());
                Log.e(editable.toString(), "added to array");

            }
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub

            }
        });

        }}
}
public类inputpage扩展活动{
public static int editCount=10;//需要根据光标拉取的项目数量动态设置,但在我有更多代码之前使用10
公共线路布局;
静态映射inputValues=新LinkedHashMap();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.inputlayout);
editlayout=(LinearLayout)this.findViewById(R.id.editlayout);
buildRow();
}
public void buildRow(){
LayoutParams textpram=新的LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
LayoutParams editparam=新的LayoutParams(350,LayoutParams.WRAP_内容);
textparam.setMargins(2,2,2,2);
对于(int i=0;i
我以前使用的代码是

public class editpage extends ListActivity {
    private dbadapter mydbhelper;
    private PopupWindow pw;
    public static SimpleCursorAdapter editadapter;
    public static ArrayList<String> editTextList = new ArrayList<String>();
    private ArrayList<EditText> m_edit = new ArrayList<EditText>();
    public static Map<Integer,String> myList=new LinkedHashMap<Integer,String>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_list);
        m_edit.clear();
        mydbhelper = new dbadapter(this);
        mydbhelper.open();
        fillData();

        }

    }
    //size of adapter and arrays
    public static int getCount(){
        return editadapter.getCount();
    }

    public void fillData() {
    Cursor e = mydbhelper.getUserWord();
        startManagingCursor(e);
        String[] from = new String[] {dbadapter.KEY_USERWORD,};
        int[] to = new int[] {R.id.textType,};
       editadapter = new SimpleCursorAdapter(this, R.layout.edit_row, e, from, to);
       ListView list = getListView();
       View footer = getLayoutInflater().inflate(R.layout.footer_layout, list, false);
       list.addFooterView(footer);
       setListAdapter(editadapter);}

                }
public类editpage扩展ListActivity{
私有数据库适配器mydbhelper;
私人PopupWindow pw;
公共静态SimpleCursorAdapter编辑适配器;
公共静态ArrayList editTextList=新建ArrayList();
private ArrayList m_edit=new ArrayList();
public static Map myList=new LinkedHashMap();
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_列表);
m_edit.clear();
mydbhelper=newdbadapter(this);
mydbhelper.open();
fillData();
}
}
//适配器和阵列的大小
公共静态int getCount(){
返回editadapter.getCount();
}
公共数据(){
游标e=mydbhelper.getUserWord();
开始管理光标(e);
String[]from=新字符串[]{dbadapter.KEY_USERWORD,};
int[]to=newint[]{R.id.textType,};
editadapter=new SimpleCursorAdapter(此,R.layout.edit_行,e,from,to);
ListView list=getListView();
视图页脚=GetLayoutFlater()。充气(R.layout.footer\u布局,列表,false);
list.addFooterView(页脚);
setListAdapter(editadapter);}
}

我找不到任何关于如何实现这一点的好资源,所以我希望这里有人知道我可以构建的链接或模拟代码

我花了一段时间,但我得到了它,所以我想我会发布,以防其他人需要此信息。我花了一段时间才找到正确方向的提示。请注意,我更改为tablelayout以获得接近所需布局的内容

public class inputpage extends Activity {

    public TableLayout tl;
    static Map<Integer, String> inputValues = new LinkedHashMap<Integer, String>();
    private dbadapter mydbhelper;
    public static int editCount;
    public Cursor cursor;

    @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    mydbhelper = new dbadapter(this);
    mydbhelper.open();
    setContentView(R.layout.tablelayout);
    tl=(TableLayout) this.findViewById(R.id.table);
    cursor = mydbhelper.getUserWord();
    editCount = cursor.getCount();
    buildRow();






    }
    public void buildRow(){

        LayoutParams textparam = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
        LayoutParams editparam = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
        textparam.setMargins(2, 2, 2, 2);
        LayoutParams rowparam = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
        cursor.moveToFirst();
        for (int i = 0; i < editCount; i++){
            TableRow tr = new TableRow(this);
            tr.setLayoutParams(rowparam); 

            //textview
            TextView tv=new TextView(this);
            tv.setLayoutParams(textparam);
            tv.setText(cursor.getString(cursor.getColumnIndex("userword")));
            tv.setTextSize(35);
            tv.setGravity(Gravity.CENTER);
            tv.setTextColor(getResources().getColor(R.color.black));
            tr.addView(tv);

            //edittext
            EditText edit = new EditText(this);
            edit.setLayoutParams(editparam);
            tr.addView(edit);
            edit.setId(editCount);
            edit.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable editable) {
                //unfinished and confirmed to work atm
                            Log.e(String.valueOf(editCount), "Position in array");
                inputValues.put(editCount, editable.toString());
                Log.e(editable.toString(), "added to array");


            }
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub

            }
        });
            cursor.moveToNext();
            tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
        }}

}
public类inputpage扩展活动{
公共桌面布局;
静态映射inputValues=新LinkedHashMap();
私有数据库适配器mydbhelper;
公共静态整数编辑计数;
公共光标;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
mydbhelper=newdbadapter(this);
mydbhelper.open();
setContentView(R.layout.tablelayout);
tl=(TableLayout)this.findviewbyd(R.id.table);
cursor=mydbhelper.getUserWord();
editCount=cursor.getCount();
buildRow();
}
public void buildRow(){
LayoutParams textpram=新建TableRow.LayoutParams(TableRow.LayoutParams.FILL\u父级,TableRow.LayoutParams.WRAP\u内容);
LayoutParams editparam=新建TableRow.LayoutParams(TableRow.LayoutParams.FILL\u父级,TableRow.LayoutParams.WRAP\u内容);
textparam.setMargins(2,2,2,2);
LayoutParams rowparam=新建TableRow.LayoutParams(TableRow.LayoutParams.FILL\u父级,TableRow.LayoutParams.WRAP\u内容);
cursor.moveToFirst();
对于(int i=0;i