Hi Guys
I have come across a problem where EditText is not rendering correctly when
it's added as a header in a ListView.
Basically, I have a search box and a list of results from a DB. The Activity
extends ListActivity and I add the search
box as a header using ListView.addHeaderView(View v).
On first load, the EditText view acts as normal. Every time I type a
character, it renders in the EditText. On any subsequent load of the
ListView, the EditText view "appears" unresponsive. If, for example, I type
another character, it does not render in the EditText view. However,
when the ListView is updated, the EditText view updates with the relevant
changes. I get the same behaviour if I change the orientation
of the screen. When I type in EditText, the characters are not rendered to
the view. If I change orientation however, the EditText view is updated.
Any help in this regard would be very much appreciated.
Below is a code example to illustrate the problem.
==============================
public class ResultList extends ListActivity {
DBAdapter mDb;
EditText mQuery;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDb = new DBAdapter(this);
mDb.open();
setContentView(R.layout.search_list);
renderUI();
populateResults("all");
}
protected void renderUI(){
TableLayout headerTable = new TableLayout(this);
headerTable.setBackgroundColor(Color.WHITE);
headerTable.setStretchAllColumns(true);
TableRow row = new TableRow(this);
row.setMinimumHeight(8);
headerTable.addView(row);
row = new TableRow(this);
row.setGravity(Gravity.CENTER_VERTICAL);
mQuery = new EditText(this);
mQuery.setWidth(180);
mQuery.setHint("Search ");
row.addView(mQuery);
ImageButton search = new ImageButton(this);
Bitmap bitmap =
BitmapFactory.decodeResource(getResources(),R.drawable.search);
search.setImageBitmap(bitmap);
search.setBackgroundColor(0);
search.setPadding(10, 0, 0, 0);
search.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
populateResults(mQuery.getText().toString());
}
});
row.addView(search);
headerTable.addView(row);
ListView list = (ListView)findViewById(android.R.id.list);
list.addHeaderView(headerTable);
}
private void populateResults(String search){
if(!mDb.getDatabase().isOpen())
mDb.open();
Cursor expCur = mDb.getResults(search);
startManagingCursor(expCur);
String[] from = new String[] { mDb.KEY_DATE_STRING_VALUE};
int[] to = new int[] { R.id.result_row_date};
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, R.layout.result_rows, expCur,
from, to);
setListAdapter(adapter);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---