Skip to content

Commit

Permalink
Merge pull request #1 from alfredayibonte/feat/EditText
Browse files Browse the repository at this point in the history
add EditText example
  • Loading branch information
alfredayibonte authored May 8, 2017
2 parents 9e2b347 + 3eab356 commit ff70fac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.alfredayibonte.questionnaireview;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.alfredayibonte.questionnaireviewlib.QuestionnaireView;
import com.alfredayibonte.questionnaireviewlib.adapters.CheckListAdapter;
import com.alfredayibonte.questionnaireviewlib.adapters.RadioListAdapter;
Expand All @@ -12,17 +18,18 @@

public class MainActivity extends AppCompatActivity implements
CheckListAdapter.OnCheckItemClickListener,
RadioListAdapter.OnRadioItemClickListener {
RadioListAdapter.OnRadioItemClickListener, TextView.OnEditorActionListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
QuestionnaireView questionnaireView = (QuestionnaireView)findViewById(R.id.questionnaire);
questionnaireView.setQuestion("What is the name of moses' father ?");
questionnaireView.setViewType(AnswerType.RADIO);
questionnaireView.setViewType(AnswerType.EDITTEXT);
questionnaireView.addRadioItemListener(this);
questionnaireView.addCheckItemListener(this);
questionnaireView.addOnEditorActionListener(this);
}

@Override
Expand All @@ -34,4 +41,10 @@ public void onCheckItemClick(List<Answer> answers) {
public void onRadioItemClick(List<Answer> answers) {
Log.e("radio answers: ", answers.toString());
}

@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {

return (i == EditorInfo.IME_ACTION_DONE);
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:question="What is your name"
app:view_type="radio"
app:entries="@array/answers"
app:view_type="text_input"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Color;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ListView;
Expand Down Expand Up @@ -77,7 +78,7 @@ private void drawInnerViews(Context context, AttributeSet attrs){
addView(listView );

//creation & addition of editText
editTv = new EditText(context, attrs);
editTv = new EditText(context);
editTv.setVisibility(GONE);
editTv.setId(android.R.id.text1);
editTv.setLayoutParams(
Expand All @@ -89,7 +90,8 @@ private void drawInnerViews(Context context, AttributeSet attrs){
.create()
);
editTv.setInputType(InputType.TYPE_CLASS_TEXT);
// editTv.setImeOptions(IME);
editTv.setImeOptions(EditorInfo.IME_ACTION_DONE);
addView(editTv );

}

Expand Down Expand Up @@ -135,10 +137,6 @@ public void setViewType(int viewType){

}

public void addOnEditorActionListener(EditText.OnEditorActionListener editorActionListener){
editTv.setOnEditorActionListener(editorActionListener);
}


public List<Answer> getAnswers(){
return this.question.getAnswers();
Expand Down Expand Up @@ -186,6 +184,15 @@ public void addRadioItemListener(RadioListAdapter.OnRadioItemClickListener radio
radioAdapter.addListener(radioListener);
}

public void addOnEditorActionListener(EditText.OnEditorActionListener editorActionListener){
editTv.setOnEditorActionListener(editorActionListener);
}

public String getResponseFromEditText(){
return editTv.getText().toString();
}



private void makeListViewVisible(){
listView.setVisibility(VISIBLE);
Expand Down

0 comments on commit ff70fac

Please sign in to comment.