【问题标题】:Dynamic edittext passed to string for another activity动态edittext传递给另一个活动的字符串
【发布时间】:2012-02-04 01:34:37
【问题描述】:

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

以列表视图的形式显示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);

【问题讨论】:

    标签: android regex database listview android-edittext


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多