I am using a custom base adapter to implement a customListView. The listView class (extends ListView) is used within a flipper flipper.addView(mListView) in the main activity.
The list View has 3 types of rows.
The 1 st in the list is a row with spinner, the next 2 are rows with edittext where text is inputed. The 3rd row and beyond are all the same with an edittext that has numbers in it.
I wanted to make it so that when I click on the text version the softkeypad will appear with the text only and for the number version the phone keypad.
They display ok but the problem comes when you click on an edittext, the softkeyboard pops up fine in the phone format.
It is all setup and values set within getView() but when the softkeyboard pops up in the phone format getView() gets called again (logical) but as soon as it hits 1 of the text type EditTexts the keyboard type switches back to text input. It will cannot easily be turned back to a phone style display after that. The view appears to be jumping around and struggling to focus on the EditText I want
I am really lost here and can't figure this out.
Here are the 2 main bits of code.
public class MethodEditorAdapter extends BaseAdapter{
private Context context;
private ArrayList<String[]> scanparam;
private LayoutInflater mInflater;
public MethodEditorAdapter(Context context, ArrayList<String[]> scanparam ) {
super();
this.scanparam = scanparam;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public long getItemId(int position) {
int i = 0;
if(position == 0) i = 0;
if(position ==1) i = 1;
if(position == 2)i = 1;
if (position > 2)i = 2;
return i;
}
@Override
public int getViewTypeCount() {
return 3;
}
@Override
public int getItemViewType(int position) {
int i = 0;
if(position == 0) i = 0;
if(position ==1) i = 1;
if(position == 2)i = 1;
if (position > 2)i = 2;
return i;
}
public View getView(int position, View convertView, ViewGroup parent) {
Formatnames(position);
View rowView = convertView;
ViewHolder holder = null;
int type = getItemViewType(position);
if (rowView == null ) {
holder = new ViewHolder();
switch (type) {
case 0:
rowView = mInflater.inflate(R.layout.method_editor_row_spin, null);
holder.paramname = (TextView) rowView.findViewById(R.id.techniquetag);
holder.techniquespinner = (Spinner) rowView.findViewById(R.id.techniquespinner);
break;
case 1:
rowView = mInflater.inflate(R.layout.method_editor_row_text, null);
holder.paramname = (TextView) rowView.findViewById(R.id.paramnameT);
holder.paramvalue = (EditText) rowView.findViewById(R.id.paramvalT);
break;
case 2:
rowView = mInflater.inflate(R.layout.method_editor_row_number, parent, false);
holder.paramnameNum = (TextView) rowView.findViewById(R.id.paramnameN);
holder.paramvalueNum = (EditText) rowView.findViewById(R.id.paramvalN);
break;
}
rowView.setTag(holder);
}else {
holder = (ViewHolder) rowView.getTag();
}
setSelectedPosition(position);
switch (type) {
case 0:
holder.paramname.setText(namestg + " " + nd);
holder.techniquespinner.setSelection(Integer.valueOf(scanparam.get(position)[1]));
break;
case 1:
holder.paramname.setText(namestg + " " + nd);
holder.paramvalue.setText(scanparam.get(position)[1]);
break;
case 2:
holder.paramnameNum.setText(namestg + " " + nd);
holder.paramvalueNum.setText(scanparam.get(position)[1]);
}
return rowView;
}
static class ViewHolder {
public TextView paramname;
public EditText paramvalue;
public Spinner techniquespinner;
public TextView paramnameNum;
public EditText paramvalueNum;
}
the main view
public class MethodEditorView extends ListView {
private ArrayList<String[]> thismethod = new ArrayList<String[]>();
public MethodEditorAdapter editorAdapter;
private ListView mListView;
private Context mContext;
public MethodEditorView(Context context, ArrayList<String[]> methodlist) {
super(context);
// TODO Auto-generated constructor stub
this.thismethod = methodlist;
mContext = context;enter code here
initview(context);
}
private void initview(Context context){
editorAdapter = new MethodEditorAdapter(context, thismethod );
this.setAdapter(editorAdapter);
}
}
the xml, sorry I couldn't insert it properly. this is for the number type.
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:id="@+id/methodrownumber">
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16sp" android:textStyle="bold" android:id="@+id/paramnameN" android:layout_width="fill_parent" android:padding="5dp"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="16sp" android:layout_weight="1" android:id="@+id/paramvalN" android:imeOptions="actionNext" android:inputType="phone" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true"></EditText>