我已經嘗試setFocusable
,setItemsCanFocus
,android:descendantFocusability="blocksDescendants"
,android:focusable="false"
,
但它不工作。的Android的ListView setOnItemClickListener不wroking
的ListView在等級[在該類別i創建列表視圖對象,並打印上點擊一個烤麪包,但其不工作]
ListView listviewobj;
listviewobj = (ListView) findViewById(R.id.location1_list);
Location_adapter adapter = new Location_adapter(Location1.this);
listviewobj.setAdapter(adapter);
Toast.makeText(Location1.this, "clicked", Toast.LENGTH_SHORT).show();
listviewobj.setOnItemClickListener(new ListView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(Location1.this, "clicked", Toast.LENGTH_SHORT).show();
}
});
public class Location_adapter extends BaseAdapter {
Context context;
public Location_adapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 2;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
class Holder {
LinearLayout ll;
ImageView img;
TextView name, adress, rating, icon;
}
@Override
public View getView(int position, View viewcontainer, ViewGroup parent) {
// TODO Auto-generated method stub
View view = viewcontainer;
Holder holder = null;
if (view == null) {
LayoutInflater inflater = ((Activity) context)
.getLayoutInflater();
view = inflater.inflate(R.layout.locationlistitem, parent,
false);
holder = new Holder();
holder.ll = (LinearLayout) view
.findViewById(R.id.location_list_item_star);
holder.img = (ImageView) view
.findViewById(R.id.location_list_item_img);
holder.name = (TextView) view
.findViewById(R.id.location_list_item_shop);
holder.adress = (TextView) view
.findViewById(R.id.location_list_item_address);
holder.rating = (TextView) view
.findViewById(R.id.location_list_item_rating);
holder.icon = (TextView) view
.findViewById(R.id.location_list_item_fvt_icon);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
holder.img.setImageResource(R.drawable.star2);
holder.name.setText("Norve coffee shop");
holder.adress.setText("Lahore");
holder.rating.setText("0.1 M");
holder.icon.setBackgroundResource(R.drawable.like);
return view;
}
適配器[其中設置值項其列表視圖適配器]
}
的ListView在佈局[列表視圖中線性佈局創建]
<LinearLayout
android:id="@+id/location1_listlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8.35"
android:visibility="gone" >
<ListView
android:id="@+id/location1_list"
android:layout_width="match_parent"
android:divider="#DEDEDE"
android:dividerHeight="1dp"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
試試這個到您的主佈局'locationlistitem'' android:descendantFocusability =「blocksDescendants」' –
@SimplePlan仍然不能正常工作 –
您的廣告apter得到什麼都不做,只是說:P – zgc7009