我在ListView中有EditText和TextView的自定义行。首先显示TextView,当用户点击TextView时,它应该转换为Edittext。我试过这个
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View myView,
int index, long mylng) {
TextView lastTextBox;
EditText lastEditBox;
for (int count = 0; count < adapter.getCount(); count++) {
lastEditBox = (EditText) listView.getChildAt(
count).findViewById(R.id.NameEditTxt);
lastTextBox = (TextView) listView.getChildAt(
count).findViewById(R.id.NameTxt);
if (count != index) {
lastTextBox.setVisibility(View.VISIBLE);
lastEditBox.setVisibility(View.GONE);
if (isChanged
&& !(lastEditBox.getText().toString()
.equalsIgnoreCase(""))) {
String modifiedData = lastEditBox.getText()
.toString();
dataModel = arrayList.get(index);
dataModel.setName(modifiedData);
lastTextBox.setText(dataModel.getName());
dNames[prevIndex]=dataModel.getName();
System.out.println("01-----------"+prevIndex);
isChanged = false;
}
} else {
String data;
lastEditBox.setVisibility(View.VISIBLE);
lastTextBox.setVisibility(View.GONE);
data = lastTextBox.getText().toString();
lastEditBox.setText(data);
isChanged = true;
}
lastEditBox.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
hideSoftKeyboard(lastEditBox);
return true;
}
return false;
}
});
}
prevIndex = index;
System.out.println("02-----------"+prevIndex);
}
});
我想在TextView中替换用户输入的数据,我无法获取上一行索引。 有什么想法解决这个问题吗?