我有表格布局,我在其中动态添加文本视图。
我在文本视图上设置 OnTouch 侦听器。
在MotionEvent.ACTION_DOWN
我显示弹出窗口和MotionEvent.ACTION_UP
。我正在删除该弹出窗口,但我希望如果从文本视图中删除触摸,那么
我尝试过的弹出窗口也应该删除MotionEvent.ACTION_MOVE
,MotionEvent.ACTION_OUTSIDE
但两者都不起作用
public void addButton_with_filter(final Test test,
TableRow.LayoutParams rowParams, Activity context) {
ArrayList<Integer> filteredquestionno;
TableLayout tl = new TableLayout(context);
tl.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
LinearLayout filterlayout = (LinearLayout) findViewById(R.id.filterlayout);
filterlayout.removeAllViewsInLayout();
filterlayout.setBackgroundResource(R.drawable.background1);
int j = 0;
int k = 0;
filteredquestionno = getLayoutFilteredQuestionNumber(test
.getQuestions());
int size = filteredquestionno.size();
if (size == 0) {
Toast.makeText(this,
"NO QUSTION IS AVAILABLE OF THIS FILTER TYPE !",
Toast.LENGTH_LONG).show();
}
int norows = (size / 10) + 1;
{
for (int i = 0; i < norows; i++) {
TableRow currentRow = new TableRow(FilterActivity.this);
// currentRow.setBackgroundResource(R.drawable.background1);
while (j < 10 && k < size) {
j++;
final TextView qindex = new TextView(FilterActivity.this);
qindex.setGravity(Gravity.CENTER);
int index = filteredquestionno.get(k);
Question question = test.getQuestionAtIndex(index);
if (question != null) {
if (submited == true) {
if (question.isSkipped()) {
qindex.setBackgroundResource(R.drawable.skipped_answer);
} else if (question.isCorrectlyAnswered()) {
qindex.setBackgroundResource(R.drawable.correct_answer);
} else if (question.isAttempted()) {
qindex.setBackgroundResource(R.drawable.wrong_answer);
} else {
qindex.setBackgroundResource(R.drawable.unattempted_question);
}
} else if (submited == false) {
if (question.isSkipped()) {
qindex.setBackgroundResource(R.drawable.skipped_answer);
} else if (question.isAttempted()) {
qindex.setBackgroundResource(R.drawable.attempted_question);
} else {
qindex.setBackgroundResource(R.drawable.unattempted_question);
}
enter code here }
} else {
qindex.setBackgroundResource(R.drawable.unattempted_question);
}
qindex.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
qindex.setTextSize(11);
if ((index + 1) < 10) {
qindex.setText("0" + (index + 1));
} else {
qindex.setText("" + (index + 1));
}
k++;
qindex.setId(k);
qindex.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
String text = (String) qindex.getText();
String t = text.trim();
int questionindex = Integer.parseInt(t);
LayoutInflater questionbutton_inflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View questionbutton_view = questionbutton_inflater
.inflate(R.layout.filterbutton, null);
final PopupWindow questiontext_popupwindow = new PopupWindow(
questionbutton_view,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
questiontext_popupwindow
.setContentView(questionbutton_view);
TextView tv = (TextView) questionbutton_view
.findViewById(R.id.texttoadd);
tv.setText(text);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
questiontext_popupwindow.showAsDropDown(qindex,
0, -125);
}
if (event.getAction() == MotionEvent.ACTION_UP) {
questiontext_popupwindow.dismiss();
test.setLastQuestionAttempted(questionindex - 1);
FilterActivity.this.finish();
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
questiontext_popupwindow.dismiss();
}
return true;
}
});
currentRow.addView(qindex, rowParams);
}
j = 0;
tl.addView(currentRow);
}
filterlayout.addView(tl);
}