开发者

ListView selection problem with rating control?

开发者 https://www.devze.com 2023-03-05 15:02 出处:网络
friends, i have created very simple custom listview adapter with ratingBar in it. now i have noticed one thing i cannot rat开发者_如何学Goe those rating bars in listview because

friends,

i have created very simple custom listview adapter with ratingBar in it.

now i have noticed one thing i cannot rat开发者_如何学Goe those rating bars in listview because when i click on listview that row particular row gets selected.

any one guide me how to select individual items in android listview?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ListView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/android:list"
    />
</LinearLayout>

and listview_item design

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:orientation="horizontal"
  android:layout_height="wrap_content">
  <LinearLayout
  android:layout_width="265dip"
  android:orientation="vertical"
  android:layout_height="wrap_content">
  <TextView android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/text1"
  android:textSize="25dip"
  android:text="This is text1"/>
  <TextView android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/text2"
  android:text="This is text2"/>
  <RatingBar android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  style="?android:attr/ratingBarStyleSmall"
  android:id="@+id/star"
  android:numStars="10"
  android:stepSize="0.1"
  android:isIndicator="true"
  />
  </LinearLayout>
 </LinearLayout>

any help would be appreciated.


Dear UMAR In order to implement the listeners to the each element to the listview(Single row) use Custom adapter and in the getview(....) method of the custom adapter ,implements the listeners which u want.. sample code `public class FindFriendsListAdapter extends BaseAdapter {

private  ArrayList<SingleElementDetails> allElementDetails;

private LayoutInflater mInflater;
private Context context;
private String userid1;
private int usersno1;
private DBAdapter db;
public FindFriendsListAdapter(Context context, ArrayList<SingleElementDetails> results,String userid,int usersno) {
    this.context=context;
    this.userid1=userid;
    this.usersno1=usersno;
    allElementDetails = results;
    mInflater = LayoutInflater.from(context);
    db=new DBAdapter(context);
    db.open();
}
public int getCount() {
    return allElementDetails.size();        
}
public Object getItem(int position) {
    return allElementDetails.get(position);
}
public long getItemId(int position) {
    return position;
}
public View getView(final int position, View convertView, ViewGroup parent) 
{
    convertView = mInflater.inflate(R.layout.friendlisthelper, null);
    ImageView imageview = (ImageView) convertView.findViewById(R.id.friendimageview);
    TextView textview = (TextView) convertView.findViewById(R.id.friendtextview);
    Button button=(Button)convertView.findViewById(R.id.friendbutton);

    convertView.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
            //do what u want
        }
    });
    button.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
           // do what u want
        }
    });
    return convertView;
}     

} `


android:isIndicator="false" in order to rate it. and listview selection will be gone automatically and control will be transferred to that rating control.


Try this

 ListView lv_party;
lv_party.setOnItemClickListener(new OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> parent, View view, final int position,long id)
        {
            // TODO Auto-generated method stub

                    view.findViewById(R.id.btn_del).setOnClickListener(new View.OnClickListener(){
//your code     
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号