0
我對此感到迷茫。嘗試從列表視圖中獲取編輯文本,並將其放入一個數組列表中以便用於其他活動。Edittext僅將第一項添加到arraylist <string>
public class editpage extends ListActivity {
public static String editString;
private dbadapter mydbhelper;
public static ArrayList<String> editTextList = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_list);
mydbhelper = new dbadapter(this);
mydbhelper.open();
fillData();
}
public void fillData() {
Cursor e = mydbhelper.getUserWord();
startManagingCursor(e);
String[] from = new String[] {dbadapter.KEY_USERWORD,};
int[] to = new int[] {R.id.textType,};
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);
}
public void onClick(View footer){
final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
final EditText editText = (EditText) findViewById(R.id.editText);
for (int i = 0; i < getCount(); i++){
editTextList.add(editText.getText().toString());
}
editClickSound.start();
startActivity(new Intent("wanted.pro.madlibs.OUTPUT"));
};
//can't get my getcount to work dynamically. I want it to be based off how many items are shown in next code showing my cursor but can't get to work atm unless I set statically to prevent errors and move to next activity
private int getCount() {
// TODO Auto-generated method stub
return 10;
}
Cursor to filter data pulled from database
public Cursor getUserWord()
{
return myDataBase.query(USER_WORD_TABLE, new String[] {
KEY_ID,
KEY_CATEGORY,
KEY_SOURCE, KEY_TITLE, KEY_USERWORD
},
KEY_CATEGORY+ "=" + categories.categoryClick + " AND " + KEY_SOURCE+ "="
+source.sourceClick + " AND " + KEY_TITLE+ "=" + title.titleClick,
null, null, null, KEY_ID);
光標從數據庫中篩選數據以列表視圖
public Cursor getUserWord()
{
return myDataBase.query(USER_WORD_TABLE, new String[] {
KEY_ID,
KEY_CATEGORY,
KEY_SOURCE, KEY_TITLE, KEY_USERWORD
},
KEY_CATEGORY+ "=" + categories.categoryClick + " AND " + KEY_SOURCE+ "="
+source.sourceClick + " AND " + KEY_TITLE+ "=" + title.titleClick,
null, null, null, KEY_ID);
}
我的下一個活動還將展示的EditText合併,從我的數據庫字符串顯示。我把這個字符串和替換以前的活動
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();
}
private final Runnable mTask = new Runnable(){
public void run(){
TextView textView = (TextView)findViewById(R.id.outputText);
String story = textView.getText().toString();
CharSequence modifitedText1 = Replacer.replace(story,
"edit01", Html.fromHtml("<font color=\"red\">"+ editpage.editTextList.get(0) +"</font>"));
CharSequence modifitedText2 = Replacer.replace(modifitedText1,
"edit02", Html.fromHtml("<font color=\"red\">"+ editpage.editTextList.get(1) +"</font>"));
textView.setText(modifitedText2);
}
};
private final Handler mHandler = new Handler();
private void fillData() {
Cursor st = mydbhelper.getStory();
startManagingCursor(st);
String[] from = new String[] {dbadapter.KEY_TITLESTORY};
int[] to = new int[] {R.id.outputText};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, R.layout.out_row, st, from, to);
setListAdapter(adapter);
}
@Override
protected void onResume() {
mydbhelper.open();
mHandler.postDelayed(mTask, 10);
super.onResume();
}
@Override
protected void onPause() {
mydbhelper.close();
super.onPause();
}
}
最遠的我能得到這個工作,是一項edit01,edit02等來自的EditText領域的用戶輸入。我將在這裏展示的第一個活動中從4-10個edittext中獲取任何地方。但不管我嘗試過什麼,它只會顯示輸入到第一個edittext字段的文本。在當前狀態下,它將在數據庫的字符串中填入edit01 & edit02與之前活動的第一個edittext中放入的內容。
經過一番研究,似乎我一直在調用相同的editText來存儲數組。但即使有了這些知識,我依然無法在沒有錯誤的情況下開展工作,錯誤地告訴我我已經走出了界限。所以看來我可以把它存儲一遍又一遍或者沒有項目。我真的希望有人能幫助。 – maebe 2012-02-09 05:35:21