相同的ID我創建使用XML和添加編輯文本提交,在列表視圖中的適配器類.IM使用enumerator.by這我能創建兩個文本框與同樣id.the問題是如何從文本字段得到的字符串,因爲它們共享相同的id.below是代碼。如何從多個編輯文本的文本與機器人
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = null;
AddKeywordRow row = keywordRows.get(position);
switch (row.getRowType()) {
case TitleRow:
rowView = inflater.inflate(R.layout.titlerow, null);
TextView txtTitle = (TextView) rowView.findViewById(R.id.rowtitle);
txtTitle.setText(row.getMessage());
break;
case EditRow:
rowView = inflater.inflate(R.layout.editrow, null);
txtInput = (EditText) rowView.findViewById(R.id.rowedit);
txtInput.setHint(row.getMessage());
if (row.getHeight() != 0)
{
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,row.getHeight());
txtInput.setLayoutParams(layoutParams);
layoutParams.setMargins(7, 0, 7,0);
//txtInput.setLayoutParams(new LinearLayout.LayoutParams(
// LinearLayout.LayoutParams.MATCH_PARENT, row.getHeight()));
txtInput.setPadding(3,0,0,30);
}
// set padding and margin
break;
case MessageRow:
rowView = inflater.inflate(R.layout.messagerow, null);
TextView txtMessage = (TextView) rowView
.findViewById(R.id.rowmessage);
txtMessage.setText(row.getMessage());
break;
case ButtonRow:
rowView = inflater.inflate(R.layout.buttonrow, null);
Button btn = (Button)rowView.findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
}
});
break;
}
return rowView;
}
有沒有簡單的方法來做到這一點,我認爲。你必須通過你的listview中的每一個孩子,並檢查它是否有這個ID,如果這是你想要的方法。也許可以考慮使用別的東西,然後列表視圖這..這並不意味着使用這種方式。但是,就是要用來創建相同的項目列表..喜歡用表格數據的表。使用上述code..would –