1
我試圖從一個列表視圖移開一個具有相鄰的TextView和Edittext的活動。編輯文本在列表視圖給了我很多麻煩,我試圖讓我的滾動視圖看起來像一個列表視圖,但沒有任何回收問題。我已經設置了一個佈局來啓動(不是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 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);}
}
我無法找到如何做到這一點,所以我有什麼好的資源希望這裏的某個人知道我可以建立的鏈接或一些模擬代碼。