动态edittext传递给另一个活动的字符串

时间:2012-02-04 01:34:37

标签: android regex database listview android-edittext

我试图设置我的程序从列表视图中获取edittext,发送到字符串。然后使用这些字符串替换从数据库中提取的文本。因此,根据用户首先选择的内容,将有4-10个edittext供他们填写。一旦他们填写了这些编辑文本,他们将点击确认按钮,然后将它们带到下一个活动。在下一个活动中,它从edittext中获取这些字符串,它将替换从我的数据库中提取的文本。我有一个edittext工作,但我想动态设置它,所以无论我在前一个活动中有多少个edittext字段,我都会有几行来处理这个函数。

以listview形式显示edittext页面的代码

public class editpage extends ListActivity {
    public static String editstring1;
    int editCount;
    private dbadapter mydbhelper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.edit_list);
        mydbhelper = new dbadapter(this);
        mydbhelper.open();
        fillData();
    }



    private void fillData() {


        Cursor e = mydbhelper.getUserWord();
            startManagingCursor(e);

     // Create an array to specify the fields we want to display in the list (TITLE,DATE,NUMBER)
        String[] from = new String[] {dbadapter.KEY_USERWORD,};

        // an array of the views that we want to bind those fields to (in this case text1,text2,text3)
        int[] to = new int[] {R.id.textType,};

        // Now create a simple cursor adapter and set it to display
       SimpleCursorAdapter 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);
       editCount = e.getCount();
        }

        public void onClick(View footer){
            final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
            editClickSound.start();
            EditText editstory = ((EditText)findViewById(R.id.editText));
            editstring1 = editstory.getText().toString();
            startActivity(new Intent("wanted.pro.madlibs.OUTPUT"));
                    };


@Override
protected void onListItemClick(ListView list, View v, int position, long id)
{
    super.onListItemClick(list, v, position, id);

    }}

下一个代码是我的输出代码,它将显示结果

public class output extends ListActivity {
    private dbadapter mydbhelper;
    @Override
    public void onCreate(Bundle savedInstantState){
        super.onCreate(savedInstantState);
        setContentView(R.layout.outview);
        mydbhelper = new dbadapter(this);
        mydbhelper.open();
        fillData();
        mHandler.postDelayed(mTask, 10);
    }

private final Runnable mTask = new Runnable(){
    public void run(){
        TextView textView = (TextView)findViewById(R.id.outputText);
        String story = textView.getText().toString();
CharSequence modifitedText = Replacer.replace(story, 
            "edit1", Html.fromHtml("<font color=\"red\">"+ editpage.editstring1 +"</font>"));
    textView.setText(modifitedText);
    }
};
private final Handler mHandler = new Handler();


    private void fillData() {

        Cursor st = mydbhelper.getStory();
            startManagingCursor(st);

     // Create an array to specify the fields we want to display in the list (TITLE,DATE,NUMBER)
        String[] from = new String[] {dbadapter.KEY_TITLESTORY};

        // an array of the views that we want to bind those fields to (in this case text1,text2,text3)
        int[] to = new int[] {R.id.outputText};

        // Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter adapter = 
            new SimpleCursorAdapter(this, R.layout.out_row, st, from, to);
        setListAdapter(adapter);
        }


}

我的数据库中的代码看起来像这样

This is sample code from edit1. It will display the raw text before they user edit2 it. etc etc

简单地说,我无法找到/寻找有关如何让动态下载代码的帮助

EditText editstory = ((EditText)findViewById(R.id.editText));
            editstring1 = editstory.getText().toString();

CharSequence modifitedText = Replacer.replace(story, 
            "edit1", Html.fromHtml("<font color=\"red\">"+ editpage.editstring1 +"</font>"));
    textView.setText(modifitedText);

1 个答案:

答案 0 :(得分:0)

您是否在适配器中创建了EditTexts?如果你这样做,我认为你应该在你的EditTexts中添加一个onChange方法并从那里处理数据