- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的工作环境是Eclipse heliose,Android 1.6
我创建了一个成功添加列和行的 tableLayout,每个单元格都有一个 textView 和一个 EditText,我在访问每个单元格时遇到问题,需要将 addTextChangedListener 添加到单元格内的每个 editText。所以我需要将英文文本更改为印度文本。请提出解决方案
/**
* Here we are going to define the grid The Grid has 1. grid's value in the
* particular position 2.
*/
public void setGrid() {
String questionNumber[] = null;
Typeface fontface = Typeface.createFromAsset(getAssets(), "fonts/padmaa.ttf");
/*
* Table layout for the crossword elements
*/
TableLayout tableLayout = (TableLayout) findViewById(R.id.crosswordTableLayout);
tableLayout.setGravity(Gravity.TOP);
tableLayout.setBackgroundColor(Color.WHITE);
tableLayout.setScrollContainer(true);
for (int i = 0; i < sizeOfGrid; i++) {
/*
* This table row params is used to set the layout params alone we
* are not going to use this anywhere
*/
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tableRowParams.setMargins(1, 1, 1, 1);
tableRowParams.height = 30;
tableRowParams.gravity = Gravity.TOP;
/*
* Defining the row element for the crossword
*/
TableRow tableRow = new TableRow(this);
tableRow.setBackgroundColor(Color.WHITE);
tableRow.setPadding(1, 0, 0, 0);
tableRow.setGravity(Gravity.TOP);
tableRow.setLayoutParams(tableRowParams);
for (int j = 0; j < sizeOfGrid; j++) {
/*
* (1).Here we are defining headerTextView to set the clue
* numbers.
* 2).columnEditText = a edit text view used to get the user
* i/p data
*/
TextView headerTextView = new TextView(this);
columnEditText = new EditText(this);
headerTextView.setGravity(Gravity.TOP);
headerTextView.setTextSize(10);
headerTextView.setEnabled(false);
headerTextView.setHeight(30);
headerTextView.setWidth(10);
headerTextView.setTextColor(Color.BLACK);
/* Override the edittext that has been created */
columnEditText = (EditText) getLayoutInflater().inflate(R.layout.tablexml, null);
columnEditText.setHeight(30);
columnEditText.setWidth(25);
/*
* LinearLayout to arrange the two text view in a vertical
* position
*/
LinearLayout headerLinearLayout = new LinearLayout(tableRow.getContext());
headerLinearLayout.setOrientation(LinearLayout.VERTICAL);
headerLinearLayout.addView(headerTextView);
/*
* LinearLayout to arrange the first Linearlayout and Edit text
* in a horizontal position
*/
LinearLayout cellLinearLayout = new LinearLayout(tableRow.getContext());
cellLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
cellLinearLayout.addView(headerLinearLayout);
cellLinearLayout.addView(columnEditText);
/*
* Here we are setting the table's vertical border by some
* workaround methods
*/
cellLinearLayout.setLayoutParams(tableRowParams);
/*
* the column with complete black
*/
if (cellValueArr[i][j] == null) {
columnEditText.setBackgroundColor(Color.BLACK);
headerTextView.setBackgroundColor(Color.BLACK);
headerTextView.setGravity(Gravity.TOP);
tableRow.setBackgroundColor(Color.BLACK);
columnEditText.setEnabled(false);
} else {
/*
* column with values and question numbers
*/
tableRow.setBackgroundColor(Color.BLACK);
if (quesNumArr[i][j] == null) {
columnEditText.setBackgroundColor(Color.WHITE);
headerTextView.setBackgroundColor(Color.WHITE);
} else if (quesNumArr[i][j] != null) {
/*
* column without question number
*/
questionNumber = quesNumArr[i][j].split("~");
quesArrList.add(questionNumber[1]);
headerTextView.setText(questionNumber[1]);
headerTextView.setTextColor(Color.BLACK);
headerTextView.setBackgroundColor(Color.WHITE);
columnEditText.setBackgroundColor(Color.WHITE);
}
}
columnEditText.setId(i);
headerTextView.setId(i);
/* add the linear layout to the row values */
tableRow.addView(cellLinearLayout);
int childCount = tableRow.getChildCount();
System.out.println("Child Count ::" + childCount);
LinearLayout linearChild = (LinearLayout) tableRow.getChildAt(columnEditText.getId());
colText = (EditText) linearChild.getChildAt(1);
System.out.println("GET ID " + linearChild.getChildAt(1).getId());
colText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence seq, int start, int before, int count) {
// TODO Auto-generated method stub
if (seq.length() > 0 & before == 0) {
final String charSequence = String.valueOf(seq);
final String engChar = String.valueOf(seq.charAt(seq.length() - 1));
println("GUJ :: currentlatin ===> " + engChar + " :: charSequence ==>" + seq);
// Method For Type Char
List softList = conv.getSoftKeyPressForChar(engChar, getApplicationContext(), seq);
charSeq = (String) softList.get(0);
Typeface fontface1 = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/padmaa.ttf");
colText.setTypeface(fontface1, Typeface.NORMAL);
colText.setText(charSeq);
// for placing the cursor position
colText.clearFocus();
colText.requestFocus();
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("AFTER TEXT CHANGE");
}
});
}
/* add the row values to the table layout */
tableLayout.addView(tableRow);
}
}
最佳答案
我没有从整体上看代码。但是根据我最初的理解,您可以通过以下任何一种方式进行操作,
正如之前有人提到的,选择 GridView 。从问题的最后一条评论中我无法充分说明这个问题,但如果它有一些滚动问题,你可以尝试将布局边距底部设置为大约 5 dp,这样它就不会被裁剪(如果那是你的意思)
继续表布局,创建一次 TextWatcher() 并将其按顺序添加到循环中。这可能很好,如果您可以为每个元素设置 Id 或 setTag,例如,首先 editText 获取名称,“editText1”,然后是“editText2”,依此类推。所以在一个循环中,你可以根据循环索引访问每个元素。
关于android - 如何在 TableLayout 中添加 editText.addTextChangedListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10118171/
我有一个带有TextInputEditText( Material 设计组件)的简单表单,无法收听文本更改。用TextWatcher添加addTextChangedListener似乎效果为零。当我运
我有动态生成和动态添加 addTextChangedListeners 的 EditText 向量。 问题是“afterTextChanged”返回的 Editable 并没有让我知道这个监听器与哪个
一直在看其他问题,但没有一个能解决我的问题。 我有一个 editText,我需要为这个字段实现一个 addTextChangedListener,这样我就可以实时更新其他 TextView 的值。 p
我想对用户在 EditText 中键入内容使用react,所以我使用了 addTextChangedListener 方法。当用户键入单个字符时,onTextChanged 代码正在运行,一切正常。因
我有一个用于填充 ListView 的数据库。在此 ListView 上方有一个编辑文本,用户可以在其中搜索 ListView 中的项目。根据输入,我希望对 ListView 进行细化和过滤,以仅包含
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有两个编辑文本,每个都有文本观察器,当第一个 edittext 文本更改时,它会更改第二个 edittext 文本,代码似乎创建了一个循环,我可以做些什么来使文本观察器只听用户输入而不是通过代码更改
我正在尝试创建一个在每行中包含一个 EditText 的 RecyclerView。一旦文本更改,我希望它用 println 显示位置。它运行良好,直到我在主方法中运行 .notifyDataSetC
我已经尝试使用 addTextChangedListener 三天了,日志显示它是由 java.lang.NullPointerException 引起的。当我评论 addTextChangedLis
我有一个 EditText,我可以在其中监听文本的变化: editText.addTextChangedListener(new TextWatcher() { @Override
我目前正在将数据库管理器移植到 android,并且由于性能原因我喜欢仅更新已修改的属性。我正在尝试使用 addTextChangedListener 来执行此操作,以便将修改后的条目添加到列表中,但
我有一个 ListView,其中每一行都有一个 EditText 控件。我想为每一行添加一个 TextChangedListener ;一个包含额外数据的数据,说明 EditText 在哪一行。问题是
我正在尝试根据 EditText 中文本的长度来编辑 Button 的背景。如果文本的长度为 0,那么背景应该是半透明的,否则它应该是不透明的。但是,我无法动态更新按钮的背景。如果我点击屏幕上的其他地
我使用 addTextChangeListener 来过滤列表项。当用户在 editText 上输入一个字符时,项目将根据用户输入进行过滤。例如,如果用户输入“stackoverflow”,则显示所有
我是 Android 开发新手。我正面临为项目开发应用程序的死胡同。请花点时间帮助我。 问题:我正在使用 for 循环 生成一些嵌套在 LinearLayout 中的 EditText View 。
你好 friend 我正在开发一个应用程序,它包含注册 Activity 。在此 Activity 中,应用程序需要用户名和用户的其他信息。如果用户名存在与否,我希望应用程序动态显示。此外,用户类型用
我有这个代码: areasqm.addTextChangedListener(new TextWatcher() { @Override public void afterTextCh
我想在列表中搜索并再次在列表中显示结果所以我使用了 addtextchangelistener,但找不到一种方法让它与带有子文本的 ListView 一起工作 这是我的代码: package co
我正在尝试制作两个 EditText,我在其中一个 EditText 中键入任何内容,我键入的文本将显示在另一个 EditText 上。 private EditText input_a; priva
有没有我可以指定 TextChangedListener 的 EditText 属性?我知道它有 3 个方法,所以我只想像下面这样指定属性值
我是一名优秀的程序员,十分优秀!