Listview and List Selector(Urgent)

Put your problem here if it does not fit any of the other categories.

Listview and List Selector(Urgent)

Postby zeeshan » Thu Apr 03, 2008 12:36 pm

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....
Attachments
02.jpg
02.jpg (110.41 KiB) Viewed 29224 times
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Top

List

Postby zeeshan » Fri Apr 04, 2008 5:23 am

Hello any body can help me please ??? i have posted a question ...any idea ??
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby rmeph » Fri Apr 04, 2008 9:48 am

rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby zeeshan » Mon Apr 07, 2008 5:54 am

hello rmeph i unable to apply selector on listview please help me out ..
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby rmeph » Mon Apr 07, 2008 7:17 am

use setSelector() method...........
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby zeeshan » Mon Apr 07, 2008 7:22 am

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

waiting for your reply
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Top

Postby rmeph » Mon Apr 07, 2008 7:26 am

In Xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  android:listSelector="@drawable/shape_3"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4



may be it help for u.....
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby zeeshan » Mon Apr 07, 2008 7:29 am

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>
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby rmeph » Mon Apr 07, 2008 7:35 am

if possible than post u'r Listview code......
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby zeeshan » Mon Apr 07, 2008 7:37 am

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>
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby zeeshan » Mon Apr 07, 2008 8:31 am

waiting for your reply...
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby rmeph » Mon Apr 07, 2008 8:44 am

im not try this

use that

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. mText.setTextColor(new ColorStateList(
  2.  
  3.                     new int[][] {
  4.  
  5.                             new int[] { android.R.attr.state_selected },
  6.  
  7.                             new int[0],
  8.  
  9.                         }, new int[] {
  10.  
  11.                             Color.rgb(255, 128, 192),
  12.  
  13.                             Color.BLACK,
  14.  
  15.                         }
  16.  
  17.                     ));
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby zeeshan » Mon Apr 07, 2008 9:01 am

it works great ...thanks ....what about giving space or margin .between listview items
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby zeeshan » Tue Apr 08, 2008 7:16 am

hello rmeph
one more question how can i apply white border on selected item of listview ??
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Postby zeeshan » Mon Apr 21, 2008 3:31 pm

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??
zeeshan
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Mon Mar 03, 2008 6:10 am

Top
Next

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests