テキストと画像でlistViewを作成しました.今、その項目をクリック可能にしたい.setOnitemclickListenerメソッドを使用しましたが、機能していません..ここで何か間違ったことをしていると思います.
アダプタ.java
public class Adapter extends BaseAdapter {
private static final String TAG = "Adapter";
private Activity mActivity;
public ArrayList<Data> mObjects;
static class ViewHolder {
ImageView icon;
TextView title;
TextView name;
TextView review;
DownloadImageTask mTask;
// DownloadImageTask1 mTask1;
// ImageView photo;
}
public Adapter(Activity activity, ArrayList<Data> mObjects) {
this.mActivity = (Activity) activity;
this.mObjects = mObjects;
}
public void setObjects(ArrayList<Data> mObjects) {
this.mObjects = mObjects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Data item = mObjects.get(position);
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = mActivity.getLayoutInflater();
rowView = inflater.inflate(R.layout.item, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.icon = (ImageView) rowView.findViewById(R.id.image);
// viewHolder.photo = (ImageView) rowView.findViewById(R.id.photo);
viewHolder.title = (TextView) rowView.findViewById(R.id.title);
viewHolder.name = (TextView) rowView.findViewById(R.id.name);
viewHolder.review = (TextView) rowView.findViewById(R.id.status);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.title.setText(item.getmTitle());
holder.name.setText(item.getmConcatinate());
holder.review.setText(item.getmreview());
holder.icon.setBackgroundResource(R.drawable.ic_ab);
// holder.photo.setBackgroundResource(0);
holder.mTask = new DownloadImageTask(item.getmImageUrl(), holder.icon);
if (!holder.mTask.isCancelled()) {
holder.mTask.execute();
}
// holder.mTask1 = new DownloadImageTask1(item.getmImageUrl1(), holder.photo);
// if (!holder.mTask1.isCancelled()) {
// holder.mTask1.execute();
// }
return rowView;
}
@Override
public int getCount() {
return (this.mObjects.size());
}
@Override
public Object getItem(int position) {
return (this.mObjects.get(position));
}
@Override
public long getItemId(int position) {
return (position);
}
public AbsListView.RecyclerListener mRecyclerListener = new RecyclerListener( ){
public void onMovedToScrapHeap(View view) {
ViewHolder viewHolder = (ViewHolder) view.getTag();
DownloadImageTask imagetask = viewHolder.mTask;
// DownloadImageTask1 imagetask1 = viewHolder.mTask1;
if (imagetask != null) {
imagetask.cancel(true);
}
// if (imagetask1 != null) {
// // imagetask1.cancel(true);
// }
}
};
}
メインクラスでそのコンテンツを使用する
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.detectAll().penaltyLog().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile3);
name = (TextView) findViewById(R.id.textView1);
bmImage2 = (ImageView) findViewById(R.id.imageView1);
address = (TextView) findViewById(R.id.textView2);
gender = (TextView) findViewById(R.id.textView3);
loyalitypoints = (TextView) findViewById(R.id.textView7);
followers = (TextView) findViewById(R.id.textView8);
following = (TextView) findViewById(R.id.textView9);
// list13 = new ArrayList<HashMap<String, Object>>();
mListView = (ListView) findViewById(android.R.id.list);
mListView.setClickable(true);
// mListView=(ListView)findViewById(R.id.list);
mAdapter = new Adapter(this, mSource);
mListView.setAdapter(mAdapter);
Log.w("Parsing JSON Data", "Before Item click");
mListView.setRecyclerListener(mAdapter.mRecyclerListener);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {
Log.w("Parsing JSON Data", "After Item click");
}
});