andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

Listview and List Selector(Urgent)


 
       anddev.org - Android Development Community | Android Tutorials | Index -> Other Coding-Problems
Author Message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Thu Apr 03, 2008 12:36 pm    Post subject: Listview and List Selector(Urgent) Reply with quote

Hello Android Champs

1 what i want is there are some distance between the listview items as you can see
2 secondly i want to show the white textcolor on selection of an item of listview ..
3 how can i give a background of this screen i have tried using shape by drawable but ...there is only startcolor and endcolor there is no kind of middle color...any idea??

Waiting for your reply guys....



02.jpg
 Description:
 Filesize:  110.41 KB
 Viewed:  12860 Time(s)

02.jpg


Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Fri Apr 04, 2008 5:23 am    Post subject: List Reply with quote

Hello any body can help me please ??? i have posted a question ...any idea ??
Back to top
View user's profile Send private message
rmeph
Senior Developer
Senior Developer


Joined: 10 Dec 2007
Posts: 120
Location: India

PostPosted: Fri Apr 04, 2008 9:48 am    Post subject: Reply with quote

plz see it
http://www.anddev.org/interval_between_two_neighboring_items_inside_linearlayout-t644.html
and
http://devtcg.blogspot.com/2008/03/advanced-tab-activity-demo.html
may be help for u
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 07, 2008 5:54 am    Post subject: Reply with quote

hello rmeph i unable to apply selector on listview please help me out ..
Back to top
View user's profile Send private message
rmeph
Senior Developer
Senior Developer


Joined: 10 Dec 2007
Posts: 120
Location: India

PostPosted: Mon Apr 07, 2008 7:17 am    Post subject: Reply with quote

use setSelector() method...........
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 07, 2008 7:22 am    Post subject: Reply with quote

please give me the example of that drawable which i will use in the selector

waiting for your reply
Back to top
View user's profile Send private message
rmeph
Senior Developer
Senior Developer


Joined: 10 Dec 2007
Posts: 120
Location: India

PostPosted: Mon Apr 07, 2008 7:26 am    Post subject: Reply with quote

In Xml
XML:
android:listSelector="@drawable/shape_3"



may be it help for u.....
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 07, 2008 7:29 am    Post subject: Reply with quote

android:listSelector="@drawable/shape_3" i have used it many times ..yes it changes the background color ,...but does not change the text color of listeview item ..


i want to change the textcolor ..just like

http://devtcg.blogspot.com/

in the example ..he did on tabs i want to do on listview ...

i am applying this on listview but does not change any text color please help me out

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@drawable/tab_unselected"
android:state_selected="false"
android:state_pressed="false" />

<item
android:drawable="@drawable/tab_unselected"
android:state_selected="false"
android:state_pressed="true" />

<item
android:drawable="@drawable/tab_selected"
android:state_selected="true" />

</selector>
Back to top
View user's profile Send private message
rmeph
Senior Developer
Senior Developer


Joined: 10 Dec 2007
Posts: 120
Location: India

PostPosted: Mon Apr 07, 2008 7:35 am    Post subject: Reply with quote

if possible than post u'r Listview code......
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 07, 2008 7:37 am    Post subject: Reply with quote

This is the actitvity code ...


setContentView(R.layout.main);
BulletedText bt1 = new BulletedText("BROWSE COUPONS",getResources().getDrawable(R.drawable.icon_get_coupons));
BulletedText bt2 = new BulletedText("SEARCH ",getResources().getDrawable(R.drawable.icon_search_coupons));
BulletedText bt3 = new BulletedText("SAVED COUPONS",getResources().getDrawable(R.drawable.icon_save_coupons));
BulletedText bt4 = new BulletedText("MANAGE COUPONS",getResources().getDrawable(R.drawable.icon_manage_coupons));
BulletedText bt5 = new BulletedText("SETTINGS",getResources().getDrawable(R.drawable.icon_settings_coupons));
btla.addItem(bt1);
btla.addItem(bt2);
btla.addItem(bt3);
btla.addItem(bt4);
btla.addItem(bt5);
setSelection(0);
setListAdapter(btla);
setSelection(0);



this is the layout code

package com.gps.framework.rivepoint.ListView;


import com.gps.framework.rivepoint.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewInflate;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class BulletedTextView extends LinearLayout { //here i changed

private TextView mText;
private TextView mText1;
private ImageView mBullet;


public BulletedTextView(Context context) {
super(context);

}

public BulletedTextView(Context context, String text, Drawable bullet) {
super(context);

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.FILL_PARENT);

params.setMargins(5, 3, 5, 0);
this.setOrientation(HORIZONTAL);

mBullet = new ImageView(context);
mBullet.setImageDrawable(bullet);
// left, top, right, bottom
//mBullet.setPadding(5, 0, 20, 50);

mBullet.setPadding(0, 10, 25, 0);
/*addView(mBullet, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));*/


addView(mBullet, params);
mText = new TextView(context);
//mText.setBackground(R.layout.tab_indicator);
//mText.setTextColor(R.color.tab_indicator_text);
mText.setPadding(0, 0, 0, 10);
mText.setText(text);

mText.setGravity(Gravity.BOTTOM);
//mText.setBackground(R.drawable.tab_indicator);
//mText.seti

//View tab = ViewInflate.from(context).inflate(R.layout.tab_indicator, this, null);
//TextView tv = (TextView)tab.findViewById(R.id.tab_label);


addView(mText, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));



}

public void setText(String words) {
mText.setText(words);
}

public void setBullet(Drawable bullet) {
mBullet.setImageDrawable(bullet);
}




}








this is the adaptor code...


package com.gps.framework.rivepoint.ListView;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


public class BulletedTextListAdapter extends BaseAdapter {

private Context mContext;

private List<BulletedText> mItems;

private boolean isFirst;

/**
*
* @param context
*/
public BulletedTextListAdapter(Context context) {
mContext = context;
mItems = new ArrayList<BulletedText>();

}
public void clear(Context context) {
mContext = context;
mItems = new ArrayList<BulletedText>();

}
/**
*
* @param bt
*/
public void addItem(BulletedText bt) {
mItems.add(bt);
notifyDataSetChanged();
}

/**
*
* @param bti
*/
public void setListItems(List<BulletedText> bti) {
mItems = bti;
}

/**
* The number of items in the
*/
public int getCount() {
return mItems.size();
}

/**
*
*/
public Object getItem(int position) {
return mItems.get(position);
}

/**
*
*/
public boolean areAllItemsSelectable() {
return false;
}

/**
*
*/
public boolean isSelectable(int position) {
return mItems.get(position).isSelectable();
}

/**
* Use the array index as a unique id.
*/
public long getItemId(int position) {
return position;
}

/**
* Make a BulletedTextView to hold each row.
*/
public View getView(int position, View convertView, ViewGroup parent) {
BulletedTextView btv;
if (convertView == null) {
btv = new BulletedTextView(mContext, mItems.get(position).getText(),
mItems.get(position).getBullet());
} else {
btv = (BulletedTextView) convertView;
btv.setText(mItems.get(position).getText());
btv.setBullet(mItems.get(position).getBullet());
}

return btv;
}
}


this is the xml layout


<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="10sp"
>


<LinearLayout android:name="@+id/top_container"
android:orientation="horizontal" android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>

<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:src="@drawable/toplogo" android:layout_gravity="center_vertical" />

</LinearLayout>


<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/empty" />

<TextView android:layout_width="fill_parent" android:id="@+id/title"
android:layout_height="wrap_content" android:text="@string/empty"
android:layout_gravity="center_vertical" style="@style/Title_Style"
android:padding="5sp" />

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/empty" />

<TextView android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sorry! No Coupons available" />

<ListView android:id="@+id/android:list"
android:scrollbars="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview" style="@style/tabIndicatorText"
android:listSelector="@drawable/tab_indicator_text"
/>


<LinearLayout android:name="@+id/top_container"
android:orientation="horizontal" android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:src="@drawable/shape_5" android:layout_weight="1"
android:background="@drawable/shape_5" />

</LinearLayout>

</LinearLayout>
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 07, 2008 8:31 am    Post subject: Reply with quote

waiting for your reply...
Back to top
View user's profile Send private message
rmeph
Senior Developer
Senior Developer


Joined: 10 Dec 2007
Posts: 120
Location: India

PostPosted: Mon Apr 07, 2008 8:44 am    Post subject: Reply with quote

im not try this

use that

XML:
mText.setTextColor(new ColorStateList(
                 new int[][] {
                         new int[] { android.R.attr.state_selected },
                         new int[0],
                     }, new int[] {
                         Color.rgb(255, 128, 192),
                         Color.BLACK,
                     }
                 ));
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 07, 2008 9:01 am    Post subject: Reply with quote

it works great ...thanks ....what about giving space or margin .between listview items
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Tue Apr 08, 2008 7:16 am    Post subject: Reply with quote

hello rmeph
one more question how can i apply white border on selected item of listview ??
Back to top
View user's profile Send private message
zeeshan
Experienced Developer
Experienced Developer


Joined: 03 Mar 2008
Posts: 68

PostPosted: Mon Apr 21, 2008 3:31 pm    Post subject: Reply with quote

mText.setTextColor(new ColorStateList(
new int[][] {
new int[] { android.R.attr.state_selected },
new int[0],
}, new int[] {
Color.rgb(255, 128, 192),
Color.BLACK,
}
));

if i want to apply state_pressed also then i how can i do this please help me out??
Back to top
View user's profile Send private message
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Other Coding-Problems All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.