2012-02-04 64 views
2

我试图设置我的程序从列表视图中将edittext发送到一个字符串。然后使用这些字符串替换从数据库中提取的文本。因此,根据用户首先选择的内容,将会有4-10个edittext供他们填写。一旦他们填写了这些edittext,他们将点击确认按钮,让他们进入下一个活动。在下一个活动中,它从edittext中获取这些字符串,它将替换从我的数据库中提取的文本。我有一个edittext工作,但我想动态设置它,所以我有几行照顾这个功能,无论我有多少edittext字段上的活动。传递给另一个活动的字符串的动态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 

简而言之,我很难找出/找到如何使b elow代码为我动态工作

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); 

回答

0

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

相关问题