I have a custom adapter set for a Listview but my itemClickEvent is not working . I have included my adapter inside my main activity.I have tried many suggestions but havent got any solutions till yet.
public class MainActivity extends Activity {
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Model.LoadModel();
listView = (ListView) findViewById(R.id.list);
String[] ids = new String[Model.Items.size()];
for (int i= 0; i < ids.length; i++){
ids[i] = Integer.toString(i+1);
}
GraphListAdapter adapter = new GraphListAdapter (this,R.layout.list_row, ids);
listView.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class GraphListAdapter extends BaseAdapter {
private final Context context;
private final String[] Ids;
private final int rowResourceId;
public GraphListAdapter(Context context, int textViewResourceId, String[] objects) {
super();
this.context = context;
this.Ids = objects;
this.rowResourceId = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(rowResourceId, parent, false);
ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView);
TextView textView = (TextView) rowView.findViewById(R.id.dashboard_name);
TextView textView2 = (TextView) rowView.findViewById(R.id.dashboard_info);
int id = Integer.parseInt(Ids[position]);
String imageFile = Model.GetbyId(id).imageName;
textView.setText(Model.GetbyId(id).dashboardName);
textView2.setText(Model.GetbyId(id).information);
// get input stream
InputStream ims = null;
try {
ims = context.getAssets().open(imageFile);
} catch (IOException e) {
e.printStackTrace();
}
// load image as Drawable
Drawable d = Drawable.createFromStream(ims, null);
// set image to ImageView
imageView.setImageDrawable(d);
return rowView;
}
private OnItemClickListener clickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
// TODO Auto-generated method stub
System.out.println(pos);
}
};
@Override
public int getCount() {
// TODO Auto-generated method stub
return 2;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}
}
My list row contains image and text both...................