我有一个基础适配器和gridview。我用适配器gridview填充项目。当用户触摸任何项目时,我想表示祝酒。但它从未显示过。
@petey我更新了代码,我为你添加了AdapterB类。请检查。
代码:
@Override
protected void onPostExecute(final Boolean success)
{
final AdapterB ada = new AdapterB(context, WallPaperList);
gridView.setAdapter(ada);
if (progressDialog.isShowing())
{
progressDialog.dismiss();
}
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long identity) {
Toast.makeText(context,ada.getItem(position).get(POST_ID), LENGTH_LONG).show();
}
});
}
AdapterB Class:
public class AdapterB extends BaseAdapter {
private Context mContext;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public AdapterB(Context c,ArrayList<HashMap<String,String>> d) {
// TODO Auto-generated constructor stub
mContext = c;
data = d;
inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(mContext,true);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
public HashMap<String, String> getItem(int position) {
HashMap<String, String> tar;
tar = data.get(position);
return tar;
}
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
if (convertView == null) {
grid = new View(mContext);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.mygrid, parent, false);
} else {
grid = (View) convertView;
}
ImageView imageView = (ImageView) grid.findViewById(R.id.imagepart);
HashMap<String,String> tar;
tar = data.get(position);
imageLoader.DisplayImage(tar.get(FragmentB.FOTOYOL),imageView);
/*
grid.setId(Integer.parseInt(tar.get(FragmentB.POST_ID)));
grid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext,"Clicked "+position,Toast.LENGTH_LONG).show();
}
});*/
return grid;
}
}
布局Xml:
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:descendantFocusability="blocksDescendants" />
答案 0 :(得分:0)
我找到了解决方案。
我的填充项目有一个复选框。我给它一个这样的属性;
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
它的工作!但我现在不知道如何立即检查方框..如果我发现我会在这里更新。