Android :: List Item View Order Changes When Scrolling Fast In ListView
Sep 2, 2010
I am new to android, and ended up (have to) ask a question here. Let's make it simple, I simply want to make my own TextView-like (MyView extends View), This is my code:
public class MyView extends View { private Paint mPaint;
private String mText; private Bitmap mBitmap1; private Bitmap mBitmap2;
public MyView(Context context) { super(context); initView(); }
public MyView(Context context, AttributeSet attrs) { super(context, attrs);
initView(); } private final void initView() { mPaint = new Paint(); }
public void setText(String text) { mText = text; }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = measureWidth(widthMeasureSpec);
if (mBitmap1 == null) initBitmap1(measuredWidth);
int measuredHeight = measureHeight(heightMeasureSpec);
setMeasuredDimension(measuredWidth, measuredHeight);
}
private void initBitmap1(int measuredWidth) {
mBitmap1 = Bitmap.createBitmap(measuredWidth, Fonts.getHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(mBitmap1 ); canvas.drawText(mText, 0, 0, mPaint);
} private void initBitmap2() {
mBitmap2 = Bitmap.createBitmap(30, Fonts.getHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(mBitmap2); canvas.drawText(mText, 0, 0, mPaint);
} private int measureWidth(int widthMeasureSpec) {
int measuredWidth = 0; int specWidthMode = MeasureSpec.getMode(widthMeasureSpec);
int specWidthSize = MeasureSpec.getSize(widthMeasureSpec);
if (specWidthMode == MeasureSpec.EXACTLY) { measuredWidth = specWidthSize;
} else { measuredWidth = getWidth(); if (specWidthMode == MeasureSpec.AT_MOST) {
measuredWidth = Math.min(measuredWidth, specWidthSize);
} } return measuredWidth; }
private int measureHeight(int heightMeasureSpec) {
int measuredHeight = 0; int specHeightMode = MeasureSpec.getMode(heightMeasureSpec);
int specHeightSize = MeasureSpec.getSize(heightMeasureSpec);
if (specHeightMode == MeasureSpec.EXACTLY) { measuredHeight = specHeightSize;
} else { measuredHeight = 80; if (specHeightMode == MeasureSpec.AT_MOST) {
measuredHeight = Math.min(measuredHeight, specHeightSize);
} } return measuredHeight;
} @Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas); canvas.drawBitmap(mBitmap1, getLeft(), 0, mPaint);
initBitmap2(); canvas.drawBitmap(mBitmap2, getLeft(), 30, mPaint);
} }
In my code, I populate some numbers of MyView (let's say 20) in a ListActivity. My question is why mBitmap1's order changes randomly while i scroll (up-down) fastly (if I scroll slowly, this problem not occur)? mBitmap2 stays where those should be.
View 1 Replies
Sep 1, 2010
I am new to android, and ended up (have to) ask a question here, Let's make it simple, I simply want to make my own TextView-like (MyView extends View). This is my code:
public class MyView extends View { private Paint mPaint; private String mText;
private Bitmap mBitmap1; private Bitmap mBitmap2; public MyView(Context context) {
super(context); initView(); } public MyView(Context context, AttributeSet attrs) {
super(context, attrs); initView(); } private final void initView() {
mPaint = new Paint(); } public void setText(String text) { mText = text;
} @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = measureWidth(widthMeasureSpec);
if (mBitmap1 == null) initBitmap1(measuredWidth);
int measuredHeight = measureHeight(heightMeasureSpec);
setMeasuredDimension(measuredWidth, measuredHeight);
} private void initBitmap1(int measuredWidth) {
mBitmap1 = Bitmap.createBitmap(measuredWidth, Fonts.getHeight(), Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(mBitmap1 ); canvas.drawText(mText, 0, 0, mPaint);
} private void initBitmap2() { mBitmap2 = Bitmap.createBitmap(30,
Fonts.getHeight(), Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(mBitmap2;
canvas.drawText(mText, 0, 0, mPaint);}
private int measureWidth(int widthMeasureSpec) { int measuredWidth = 0;
int specWidthMode = MeasureSpec.getMode(widthMeasureSpec);
int specWidthSize = MeasureSpec.getSize(widthMeasureSpec);
if (specWidthMode == MeasureSpec.EXACTLY) { measuredWidth = specWidthSize;
} else { measuredWidth = getWidth(); if (specWidthMode == MeasureSpec.AT_MOST) {
measuredWidth = Math.min(measuredWidth, specWidthSize);
} } return measuredWidth; }
private int measureHeight(int heightMeasureSpec) {
int measuredHeight = 0; int specHeightMode = MeasureSpec.getMode(heightMeasureSpec);
int specHeightSize = MeasureSpec.getSize(heightMeasureSpec);
if (specHeightMode == MeasureSpec.EXACTLY) {
measuredHeight = specHeightSize; } else { measuredHeight = 80;
if (specHeightMode == MeasureSpec.AT_MOST) { measuredHeight = Math.min(measuredHeight, specHeightSize);
} } return measuredHeight; }
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas); canvas.drawBitmap(mBitmap1, getLeft(), 0, mPaint);
initBitmap2(); canvas.drawBitmap(mBitmap2, getLeft(), 30, mPaint); } }
View 9 Replies
View Related
Oct 17, 2010
Trying to implement simple dictionary. I want to make it so while the user is typing in the EditText box the list to scroll automatically to the best match. I don't want it to filter the list. For example if the user types "s" in the EditText I want the first word that s/he sees under the EditText box to be the first word in the dictionary that starts with "s." But the user should still be able to slide up and down and to be able to see the entire list of words. It is basically like a go to functionality. I used ArrayList to store my list of words. The data is in res/raw/data.xml file. Here is my onCreate method
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
wordListView = (ListView)findViewById(R.id.wordList);
myEditText = (EditText)findViewById(R.id.myEditText);
words = new ArrayList<Word>();
arrAdap = new ArrayAdapter<Word>(this, android.R.layout.simple_list_item_1, words);
wordListView.setAdapter(arrAdap); try {
InputStream inSource = getResources().openRawResource(R.raw.data);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(inSource, null);
NodeList wordsList = doc.getElementsByTagName("eng-bg");
int length = wordsList.getLength();
for(int i = 0; i<length; i++) {
Element entry = (Element)wordsList.item(i);
Element eng = (Element)entry.getElementsByTagName("english").item(0);
Element bul = (Element)entry.getElementsByTagName("bulgarian").item(0);
Element id = (Element)entry.getElementsByTagName("ID").item(0);
String english = eng.getFirstChild().getNodeValue();
String bulgarian = bul.getFirstChild().getNodeValue();
int wordId = Integer.parseInt(id.getFirstChild().getNodeValue());
Word word = new Word(bulgarian, english, wordId);
addNewWord(word);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}wordListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
selectedWord = words.get(pos);
showDialog(TRANS_DIALOG);
myEditText.setText(selectedWord.getEnglish());
myEditText.addTextChangedListener(new TextWatcher(){
public void onTextChanged(CharSequence s, int start, int before, int count) {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
View 1 Replies
View Related
Apr 9, 2010
I don't know exactly how to explain this problem, but I'll try. I have a ListView with several items. Each item has inside a TextView and two ImageView. I want the ImageView change when I click on them, and I want to open a context menu when I press for a long time into the ListView item.For the ImageView, everything works properly. For the whole item, I can show the context menu after a long press, but my problem is that the ImageView changes as well when I am pressing the TextView, for example.I hope you understand my problem. I think that all the children of a view are affected by an event in the parent, but I am not sure.
View 2 Replies
View Related
Apr 23, 2010
I'm trying to create a multiple selection list where the selection is represented graphically rather than with checkboxes.My list has checkboxes, but I want them to serve a different purpose. I'm using a cursor to hold my data and created a custom view binder for the SimpleCursorAdapter. I did this for the checkboxes and general flexibility.So far I haven't even been able to show one line as being selected. I've enabled multiple selection on the list and denied the children of the list item focusability. I've tried manually changing background color with the position fed in through the list item click listener. But the wrong items get changed and they don't even change to the right color. I've enabled touch focusability with no improvement either.Ideally, I'd like the trackball highlight focus bar to appear in multiple places. But I don't think this is possible unless you use the drawable directly. But I don't know how to find or apply it. My next idea was to have a slim view bar that changes color. But I had the same problem with the wrong item being selected so I never finished trying to guess the index position to see if this would work. My most recent idea is to completely swap out the view for another one if it's selected. But I have no idea how to do this either. I'm thinking of using an array list to store the _id s of the items that need a different view to get around the wierd selection problem. I'm also thinking of passing in the ID field as my from and the selection view as the to for my adapter. Then I'd intercept it with my binder and change the view accordingly. But once again, I'm not sure how to do this successfuly.
View 7 Replies
View Related
Jul 14, 2010
By Default in the Listview,focus will come on the list item.Instead of that, can I get only the border to the list item?I can achieve this by using a transparent image as a list selector.Is there any other simplest way to achieve this requirement?
View 1 Replies
View Related
Aug 31, 2010
I want to display a list item that says "More" at the end of my ListView. Clicking on this list-item will perform some action. How can I create this "more" list item?
View 3 Replies
View Related
Oct 18, 2010
I have used tab view and inside frame first view is ListView.My list view has white and blue background alternately like 1st is white, 2nd blue, 3rd white, 4th blue.I have tried disabing cachehint and even using it. But when i scroll the alternate colors are broken like we can see 2 consecutive in white or blue. Sometimes even 3 in same color. This happens when i scroll the list.
View 2 Replies
View Related
Aug 23, 2010
Basically I am trying to recreate the default contact screen when you click on "+" button another row of Phone number added to the list. Right now I have an ImageView as the "+" button and a ListView to contain the list of phone numbers. The problem is that the ListView doesn't expand when I add more item into the list. I could build the same look with LinearLayout but how can I save all those numbers that way? Below is the layout of the item that will be inflate with custom Adapter:
<?xml version="1.0" encoding="utf-8"?> <TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="60px"
android:stretchColumns="1" android:background="#FFFFFFFF"
android:gravity="center_vertical"> <TableRow>
<Button android:id="@+id/type" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingLeft="10dp"
android:text="Home" /> <RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:paddingLeft="10dp"
android:paddingRight="10dp" >
<EditText android:id="@+id/value" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:text="" android:hint="Name"
android:lines="1" android:textSize="10pt" android:typeface="sans"
android:textColor="#FF000000" android:gravity="left" /
</RelativeLayout> <ImageView android:id="@+id/del"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentTop="true"
android:paddingRight="14dp" android:src="@android:drawable/ic_delete" />
</TableRow> </TableLayout>
This is the ListView portion.
<ListView android:id="@+id/phoneList" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#FFFFFFFF"
android:scrollbars="none" />
View 2 Replies
View Related
Nov 19, 2010
A view flipper has 4 list views. When i flip the view flipper using gesture listener implemented on view flipper, it works fine. But I am not able to scroll the list view since the touch event is not able to trickle down from view flipper to list view.
CODE:.............
I want this event to be handled by list view
CODE:.................
View 2 Replies
View Related
Feb 26, 2010
The Contacts app shows a button on the side of the screen that acts as a little thumb to allow you to quickly scroll the big list. I have a very long list that would benefit from this navigation behavior, but can't find any documentation as to how to enable it.
Is it a behavior that's built into the SDK, or must I write it myself?
View 1 Replies
View Related
Apr 16, 2010
I am trying to overwrite the default backgroud color of List item which is holding the focus in the ListView. As you can see, in Android Setting Menu, when you scroll through the ListView, the focused ListItem has a red backgroud to highlight its focus. Does any way to change the default behavior by highlighting it with other color or just a bottom red line under this Item.
View 5 Replies
View Related
Nov 8, 2010
I have this Listview element:
<ListView
android:id="@+id/category_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/list_background"
android:layout_marginTop="10sp"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/list_item_background"
android:cacheColorHint="#FFFFFF"
android:clipToPadding="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"a
ndroid:longClickable="true"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:dividerHeight="1px" />
where list_background is:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp" /> <solid android:color="#FFFFFF"/>
</shape>
The list view loads itself with the rounded corners, but then, the items of the list hide the round corners.
View 2 Replies
View Related
Aug 12, 2010
We're working with a pre-release device running V2.1_update1 We have a ListView in the middle of a screen with the height set to wrap-content. On all other devices, as long as there is room on the screen, this control does not scroll--or if it does scroll, it only scrolls to the limits of the entries in the list. On this new device, there is definitely room for the list so it should not be scrolling at all, but the ListView scrolls and seems to have elastic whitespace above and below (and separator lines above the top item and below the bottom item). Thus, when you drag down, the whole list scrolls down within the limits of the view's bounds (i.e. it clips there) and then when you release the drag, the list springs back up to its normal position. This latter behavior makes it seem like there is deliberate code that has been put in for this--but we certainly didn't do that. What could cause this? Is there a setting that has defaulted one way on this device that defaults opposite on other devices?
View 2 Replies
View Related
May 21, 2009
I have the list view which is having 10 Items. I want to block few items (Disable). How do i do this? Can any one help me?
View 2 Replies
View Related
Oct 22, 2009
I have a ListView backed by customized ArrayAdapter where each item has 2 LinearLayouts - one I call head, and the other one - body. The body is hidden (gone) until user clicks on the row at which time it slides out. The second click (on the head) will hide the body. However if user clicks on the body it brings another activity. All of this works just fine, here comes the problem.When user presses on body I want a visual indication of the action just the same way as regular list item will flicker an orange background when pressed. I'm not getting this by default since (my theory) the onPress event is intercepted by body's view and not processed by the list item.The first thing I tried was to execute body.setBackground('#ff00ff') (never mind the color) in onPress event. That didn't work since (I suspect) there's no repainting after the call. Then I dig a little bit more and decided to use <selector/>-based background. I defined body_background.xml in drawable folder and assigned that to the body's background property.
There I noticed that background will only change if the even is processed by the list. For example if I set <item android:state_selected="true" android:drawable="@drawable/selected"/> then when I press on the head - the background of both elements (head and body) will change, however when I press on body - nothing. So to summarize my question.how do I change background of the child element in the list item if I assign custom onClick handler to it?
View 6 Replies
View Related
Mar 3, 2009
I have problem with the List view scrolling. Here I have a list view contains more 50 items. I am setting the list view background as transparent. While scrolling the list view it is showing with black background. Can any one tell me how to remove this black portion?
View 3 Replies
View Related
Dec 10, 2009
I'm developing an application which has an listview. I'm currently creating the list item view dynamically from code (linearlayout, which includes 2 textviews and 1 imageview), but i'd like to use an XML resource for this. I read it is resource intensive when getting this view using findViewById within a loop. I thought of using a custom adapter for this, but am not sure on how to include lazy loading of the image then.
View 4 Replies
View Related
Jan 11, 2010
How can I change the first visible item in a list view (I searched a method such as setFirstVisiblePosition) ?
View 2 Replies
View Related
Feb 13, 2010
I have a list view having several items and it is multichoice list. I want to display the checked item of list view. how i can do this.can anyone help me?
View 1 Replies
View Related
Nov 4, 2010
As I am reviewing and prototyping my android project, I noticed that there is a view that has a list of items that are very customized. I have figured out most of my tools that I plan to use but I need some advice.
I have a list of items which can contain photos, some text to the right, an image to the bottom and more text below that. Very confusing I know. Each of these might be present for an item. The only thing that will always be there is the title.
So my question - what is the best way to create each custom list item view? I am thinking I have to use this getView to create each view. But when creating each view, is it best to 1) create a view dynamically and adding an image, for example, if it exists, or 2) create an xml file with all possible elements and hide them depending on the item?
View 2 Replies
View Related
Apr 9, 2010
I want to customize list view item spaces between different items. We generally display list item with default space between them to get viewed in list.I want to customize the space difference between them so that more data can be displayed in the list within the display part at a time
View 2 Replies
View Related
Aug 12, 2010
I have a ListActivity where the list items are defined in another XML layout. The list item layout contains an ImageView, a CheckBox, a TextView and such.
What I want is to set an onClick listener to the CheckBox in each list item. That is easy enough. The trouble is I need that onClick handler to know which position in the list it is.
I'm attaching the listener to the CheckBox in getView after that convertView has been inflated. The getView method has a position parameter, but I cannot reference it in the onClick handler for my CheckBox. I understand why, but I don't know how to get around it. How do I accomplish this?
View 2 Replies
View Related
Oct 31, 2010
I am building a android aplication which will be consuming a json file from the internet. This json file contains a list of news from a particular website. Each json object contains information such like title, summary, descripition and web links for the news thumbnail and the original image.
I will be displaying in a listview three information: the news thumbnail, the title and the summary. Here resides my problem. I dont want to load all thumbnails from the internet if they wont be displayed. What I am trying to say is that why download a thumbnail from the 30th news if the user wont scroll down the image. So, i will, initially only download the thumnails from those news that are being displayed in the screen and when the user scrolls down to see more news, as soon as the list item appers to the screen i want to download the image and then display.
Is there a way to achieve this? Is it possible to find out if the list item is on the screen? I have been searching all over the internet for a solution for this but i am running out of ideas.
View 1 Replies
View Related
Sep 6, 2010
What Iīm trying to do is to create a list (using a list view) of items (which are views inflated from the same layout) what must be clickable. At first I thought that all I had to do was to add an onItemClickListener to the ListView so if the used clicked on any of the views that composed this Item the listener would react. Well, I was wrong. Iīve tried a lot of things, including setting focus and focusontouchmode off for each of the views that compose the itemīs view but it still doesnīt work. Any tips here? Can I archive this result? Oh, also ... this list view is in a dialog and the listener is in the activity that builds the dialog.
View 20 Replies
View Related
May 20, 2010
I need to implement a list view with checkbox and each item should be associated with images.
View 1 Replies
View Related
Mar 22, 2010
How to remove item from a list view? how to reload the list after removal?
View 3 Replies
View Related
Jan 20, 2010
Can anyone help with a problem I have? I created an activity (extending a list activity) and have it populating with a list of peoples names, however when I scroll up or down it automatically greys out the whole list view until you stop scrolling. Is it possible to stop this greying out from happening? I have attached an screenshot in case my description doesnt make sense. Code...
View 4 Replies
View Related
Sep 16, 2010
Trying to set ContextMenu title according to the ListView clicked item.The ListView contains Bookmarks list -> FAVICON + BOOKMARK TITLE @Override public void onCreate Context Menu (Context Menu menu, View v, ContextMenuInfo menuInfo) {super.onCreateContextMenu(menu, v, menuInfo); menu.add(0, EDIT_ID, 0, R.string.menu_edit); menu.add(0, DELETE_ID, 0, R.string .menu_delete); menu.add(0, SHARE_ID, 0, R.string.menu_share); AdapterView. Adapter ContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; View itemID = (info.targetView); menu.setHeaderTitle("bla" + itemID);when I run this code it shows the android.widget.RelativeLayout@423d2389 or whatever and if I change the itemID to String itemID = ((TextView) info.targetView).getText().toString(); I get force close on long click even though no errors are shown in Eclipse or when I run the app.I also want to get the favicon in the same way.
View 1 Replies
View Related
Sep 2, 2010
I'm just beginning Android development, and I'm working to get a Custom list view with a checkbox working. I've created a base class that extends Activity, Created an Adapter and overrode the getView() method to add the checkbox to the list view. I'm assuming I need to do this because I need something equivalent to didSelectRowIndexAtPath from Obj C to update my model. Please let me know if there's an alternate way of doing this too Code...
View 2 Replies
View Related