I'm trying to extend BaseAdapter and Edit Data in that extension. (full
source code to class is below) I'm having several focus issues. The first
issue is that I must touch the "EditText" field several times to get focus.
On the Droid X the soft keyboard never shows. On the ADP2 once I type one
letter the auto complete bar shows for a moment then disappears, then I lose
focus for the field I was just editing.
********************************************************************************************
package net.ideposit.classes;
import java.util.List;
import net.ideposit.R;
import net.ideposit.entities.DetailItem;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnFocusChangeListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
public class TransactionAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<DetailItem> DetailItems;
public TransactionAdapter(Context context,List<DetailItem> DetailItems)
{
// Cache the LayoutInflate to avoid asking for a new one each time.
mInflater = LayoutInflater.from(context);
this.DetailItems = DetailItems;
}
/**
* The number of items in the list is determined by the number of
speeches
* in our array.
*
* @see android.widget.ListAdapter#getCount()
*/
public int getCount() {
return DetailItems.size();
}
/**
* Since the data comes from an array, just returning the index is
* sufficent to get at the data. If we were using a more complex data
* structure, we would return whatever object represents one row in the
* list.
*
* @see android.widget.ListAdapter#getItem(int)
*/
public Object getItem(int position) {
return position;
}
/**
* Use the array index as a unique id.
*
* @see android.widget.ListAdapter#getItemId(int)
*/
public long getItemId(int position) {
return position;
}
/**
* Make a view to hold each row.
*
* @see android.widget.ListAdapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid
unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is
no need
// to reinflate it. We only inflate a new View when the convertView
supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.field_layout, null);
// Creates a ViewHolder and store references to the two children
views
// we want to bind data to.
holder = new ViewHolder();
holder.Di = DetailItems.get(position);
holder.Caption = (TextView)
convertView.findViewById(R.id.txtCaption);
holder.SetEditor((EditText)
convertView.findViewById(R.id.txtEditor));
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
holder.Di = DetailItems.get(position);
}
holder.Editor.setTag(holder.Di);
holder.Editor.setMinLines(holder.Di.MaxLines);
holder.Editor.setMaxLines(holder.Di.MaxLines);
holder.Editor.setInputType(holder.Di.getDefaultInputType());
if (holder.Di.Password == true){
holder.Editor.setTransformationMethod(new
PasswordTransformationMethod());
}else{
holder.Editor.setTransformationMethod(null);
}
holder.Editor.setHint(holder.Di.Hint);
holder.Editor.setText(holder.Di.Value);
holder.Caption.setText(holder.Di.Caption);
return convertView;
}
private class ViewHolder implements OnFocusChangeListener, TextWatcher {
TextView Caption;
EditText Editor;
DetailItem Di;
boolean HasFocus = false;
public void SetEditor(EditText theEditor){
if (Editor != null){
Editor.setOnFocusChangeListener(null);
Editor.addTextChangedListener(null);
}
Editor = theEditor;
Editor.setOnFocusChangeListener(this);
Editor.addTextChangedListener(this);
}
public void onFocusChange(View arg0, boolean arg1) {
HasFocus = arg1;
}
public void afterTextChanged(Editable arg0) {
// not used
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int
arg3) {
// not used
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
if (HasFocus){
Di.Value = Editor.getText().toString();
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en