Issues with ListView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Issues with ListView

Postby Jayshil » Sun Dec 20, 2009 7:35 am

Hi All,

I have problem regarding list view in ANDROID.

I have my list view inflated from an XML. Where the items have backgrounds.
Now when i traverse using the trackball the focus shown on the list view is not shown correctly because of the image used as background in the items. Is there any way in which I get to know when the list item is focussed or focussed.

If not, i have tried setting the setAlpha value for my background images of items so as to make them a bit transparent, so that focussed color behind is visible but still its very fade. And ideally i cant use this since it degrades the quality of the background image because of transparency.

I have tried doing drawSelectorOnTop for the listView, but instead of showing me the list items, it displays the orange bar and the items get hidden.

If anyone has a idea how to achieve this please let me know.
If any clarifications are required do let me know will paste the code here.

Regards,
Jayshil

P.S. Ideally speaking traversing should not be taken into consideration since its a touch phone but its the GD doesnt understand it :(
JD
Jayshil
Freshman
Freshman
 
Posts: 2
Joined: Sun Dec 20, 2009 7:25 am

Top

Postby arams » Sun Dec 20, 2009 6:08 pm

post your code
For Mobile Application Contact: www.sarmalsoft.com
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Postby Jayshil » Sun Dec 20, 2009 6:35 pm

public View getView(int position, View convertView, ViewGroup parent) {
cursor.moveToPosition( position );
if(convertView == null) {
convertView = mInflater.inflate(R.layout.inboxitemxml, null);
}
LinearLayout t_contactsList = (LinearLayout)convertView.findViewById(R.id.contacts_list);
Drawable t_item_list_def_background = m_folderListActivity.getResources().getDrawable(R.drawable.mail_node_def);
t_item_list_def_background.setAlpha(100);


//t_contactsList.setBackgroundColor(R.color.solid_white);

TextView messageView = (TextView)convertView.findViewById(R.id.buddy_message);
TextView emailView = (TextView)convertView.findViewById(R.id.buddy_email_id);
MailBox mailBox = new MailBox();
mailBox.populateData(cursor);
messageView.setText( mailBox.mail_subject );
emailView.setText( mailBox.mail_from_name );
ImageView t_envelop = (ImageView) convertView.findViewById(R.id.envelop);
if (mailBox.is_mail_read.equals("true")) {
Drawable tItem_list_def_background = m_folderListActivity.getResources().getDrawable(R.drawable.mail_node);
tItem_list_def_background.setAlpha(100);

t_contactsList.setBackgroundDrawable(tItem_list_def_background);
if (mailBox.mail_has_attachments.equals("true")) {
t_envelop.setImageResource(R.drawable.readmailatt_icon);
} else {
t_envelop.setImageResource(R.drawable.readmail_icon);
}
} else {
t_contactsList.setBackgroundDrawable(t_item_list_def_background);
if (mailBox.mail_has_attachments.equals("true")) {
t_envelop.setImageResource(R.drawable.unreadmailatt_icon);
} else {
t_envelop.setImageResource(R.drawable.unreadmail_icon);
}
}
TextView t_textField = (TextView) convertView.findViewById(R.id.size);
String t_size = mailBox.mail_size;
if (t_size.length() > 6) {
t_size = t_size.substring(0, 1) + "M";
} else if (t_size.length() > 3) {
t_size = t_size.substring(0, 1) + "K";
}

t_textField.setText(t_size);

String t_date = mailBox.mail_date_sent; //YY-MM-DD HH:MM:SEC
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
String formatedDate = dateFormat.format( date );
t_textField = (TextView) convertView.findViewById(R.id.date);
if (formatedDate.startsWith(t_date.substring(0, t_date.indexOf(' ')))) {
int t_startIndex = t_date.indexOf(" ");
int t_endIndex = t_date.lastIndexOf(':');
String t_dateToBeSet = t_date.substring(t_startIndex, t_endIndex);//"";//t_day + "/" + t_month; //MM/DD
t_textField.setText(t_dateToBeSet);
} else {
int t_startIndex = t_date.indexOf("-");
int t_endIndex = t_date.indexOf(" ");
String t_dateToBeSet = t_date.substring(t_startIndex, t_endIndex);//"";//t_day + "/" + t_month; //MM/DD
String[] t_dateValues = t_dateToBeSet.split("-");
t_dateToBeSet = t_dateValues[2]+"/"+t_dateValues[1];
t_textField.setText(t_dateToBeSet);
}

if(FolderListActivity.screen_mode == ApplicationConstants.WLScreenmode.INBOX_SCREEN_VIEW){
if (mailBox.mail_from_email != null) {
ContactsNode t_buddyNode = WindowsLiveApplication.getApplication().getContactList().getContactByEmail(mailBox.mail_from_email);
ImageView t_buddyStatus = (ImageView) convertView.findViewById(R.id.buddy_status);
if (t_buddyNode != null) { //buddy in the list
t_buddyStatus.setImageResource(WLUtil.setStatusImage(t_buddyNode.getPresentStatus()));
} else { // buddy not in the list
t_buddyStatus.setImageResource(R.drawable.non_im_contact_icon);
}
}
}else if(FolderListActivity.screen_mode == ApplicationConstants.WLScreenmode.INBOX_SCREEN_MOVE_OR_DELETE){
ImageView t_buddyStatus = (ImageView) convertView.findViewById(R.id.buddy_status);
if(mailBox.mail_selected_for_moving != null && mailBox.mail_selected_for_moving.equals( "true" )) {
t_buddyStatus.setImageResource(R.drawable.check_r1_c1);
} else {
t_buddyStatus.setImageResource(R.drawable.check_r3_c1);
}

}
convertView.setTag( mailBox );
return convertView;

}

I have highlighted the code where the background images are being set.

The xml for the list view is as below.

<ListView android:id="@+id/folder_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/solid_white" android:focusable="true" android:fadingEdge="none" android:cacheColorHint="#ffffff"/>

By doing the above setAlpha i am able to get the fadish orange of ANDROID. I want the default look. Hope this is explanatory.
JD
Jayshil
Freshman
Freshman
 
Posts: 2
Joined: Sun Dec 20, 2009 7:25 am

Postby arams » Mon Dec 21, 2009 5:02 am

did you try this:
ListView.setCacheColrHint(color);
For Mobile Application Contact: www.sarmalsoft.com
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 8 guests