我的适配器视图中有一个编辑文本。当我滚动列表视图时,我正在丢失编辑文本中输入的数据,我尝试了本网站提供的所有解决方案。但是没有工作?我怎样才能做到这一点..
这是我的焦点转换者听众..
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form3.Show;
end;
答案 0 :(得分:0)
希望这有助于你:
if (!hasFocus) {
EditText et = (EditText) v.findViewById(R.id.ur_editext);
mylist.get(position).put("data", et.getText().toString().trim());
}
答案 1 :(得分:0)
//You can achieve the expected output by using the below code .....
package mobile.sachien.com.myapplication_imageload;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
public class ListviewActivity extends Activity {
private String[] arrText =
new String[]{"Text1","Text2","Text3","Text4"
,"Text5","Text6","Text7","Text8","Text9","Text10"
,"Text11","Text12","Text13","Text14","Text15"
,"Text16","Text17","Text18","Text19","Text20"
,"Text21","Text22","Text23","Text24"};
private String[] arrTemp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lyt_listview_activity);
arrTemp = new String[arrText.length];
MyListAdapter myListAdapter = new MyListAdapter();
ListView listView = (ListView) findViewById(R.id.listViewMain);
listView.setAdapter(myListAdapter);
}
private class MyListAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
if(arrText != null && arrText.length != 0){
return arrText.length;
}
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arrText[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = ListviewActivity.this.getLayoutInflater();
convertView = inflater.inflate(R.layout.lyt_listview_list, null);
holder.textView1 = (TextView) convertView.findViewById(R.id.textView1);
holder.editText1 = (EditText) convertView.findViewById(R.id.editText1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ref = position;
holder.textView1.setText(arrText[position]);
holder.editText1.setText(arrTemp[position]);
holder.editText1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
arrTemp[holder.ref] = arg0.toString();
}
});
return convertView;
}
private class ViewHolder {
TextView textView1;
EditText editText1;
int ref;
}
}
}