朋友,
我创建了一个非常简单的自定义listview适配器,里面有ratingBar。
现在我注意到有一件事我无法对listview中的评级栏进行评分,因为 当我点击列表视图时,行特定行被选中。
任何人都指导我如何在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>
和listview_item设计
<?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>
任何帮助将不胜感激。
答案 0 :(得分:0)
亲爱的UMAR 为了实现每个元素到listview(单行)的监听器,使用自定义适配器并在自定义适配器的getview(....)方法中,实现你想要的监听器..示例代码`public class FindFriendsListAdapter扩展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;
}
} `
答案 1 :(得分:0)
android:isIndicator =“false”以便对其进行评分。列表视图选择将自动消失,控制权将转移到该评级控制。
答案 2 :(得分:-1)
试试这个
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
}