Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed TextEdit focus issue #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/QMBForm/src/main/java/com/quemb/qmbform/FormManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.quemb.qmbform.descriptor.SectionDescriptor;
import com.quemb.qmbform.descriptor.Value;
import com.quemb.qmbform.view.Cell;
import com.quemb.qmbform.view.FormEditTextFieldCell;
import com.quemb.qmbform.view.FormEditTextViewFieldCell;

import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -42,7 +44,7 @@ public FormManager(){
}


public void setup(FormDescriptor formDescriptor, final ListView listView, Activity activity){
public void setup(final FormDescriptor formDescriptor, final ListView listView, Activity activity){

Context context = activity;

Expand All @@ -53,7 +55,7 @@ public void setup(FormDescriptor formDescriptor, final ListView listView, Activi

final FormAdapter adapter = FormAdapter.newInstance(mFormDescriptor, context);
listView.setAdapter(adapter);
listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
//listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.quemb.qmbform.descriptor.SectionDescriptor;
import com.quemb.qmbform.CellViewFactory;
import com.quemb.qmbform.view.Cell;
import com.quemb.qmbform.view.FormEditTextFieldCell;

import android.content.Context;
import android.view.View;
Expand All @@ -23,17 +24,19 @@ public class FormAdapter extends BaseAdapter {
private ArrayList<FormItemDescriptor> mItems;
private Context mContext;
private Boolean mEnableSectionSeperator;
private int focusedEditTextRow = -1;

public static FormAdapter newInstance(FormDescriptor formDescriptor, Context context){
FormAdapter formAdapter = new FormAdapter();
formAdapter.mFormDescriptor = formDescriptor;
formAdapter.mContext = context;
formAdapter.setEnableSectionSeperator(true);
formAdapter.setup();

return formAdapter;
}

@Override
public int getCount() {
public void setup() {
mItems = new ArrayList<FormItemDescriptor>();
int sectionCount = 1;
for (SectionDescriptor sectionDescriptor : mFormDescriptor.getSections()){
Expand All @@ -49,7 +52,10 @@ public int getCount() {
}
sectionCount++;
}

}

@Override
public int getCount() {
return mItems.size();
}

Expand All @@ -66,9 +72,25 @@ public long getItemId(int position) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Cell cell = CellViewFactory.getInstance().createViewForFormItemDescriptor(mContext,getItem(position));
if (cell instanceof FormEditTextFieldCell) {
processEditTextCell((FormEditTextFieldCell)cell, position);
}
return cell;
}


return CellViewFactory.getInstance().createViewForFormItemDescriptor(mContext,getItem(position));
private void processEditTextCell(FormEditTextFieldCell cell, final int row) {
if (row == focusedEditTextRow) {
cell.getEditView().requestFocus();
}
cell.getEditView().setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
focusedEditTextRow = row;
}
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ public EditText getEditView() {
return mEditView;
}

public void focusEditText() {
mEditView.requestFocus();
}

}