あなたはこれを試すことができます:
CustomAdapter.class:
public class CustomAdapter extends ArrayAdapter<String>{
Context mContext;
String[] list;
LayoutInflater mInflater;
public static HashMap<Integer, Integer> hashkeys=new HashMap<Integer,Integer>();
public CustomAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
list=objects;
mInflater = LayoutInflater.from(context);
mContext=context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null)
{
convertView = mInflater.inflate(R.layout.custom_item, null);
holder = new ViewHolder();
holder.tv=(TextView)convertView.findViewById(R.id.textview);
convertView.setTag(holder);
}
else
{
holder=(ViewHolder)convertView.getTag();
}
int value=0;
switch(position){
case 0:
value=1;
break;
case 1:
value=2;
break;
case 3:
value=3;
break;
}
hashkeys.put(position,value);
return convertView;
}
static class ViewHolder
{
TextView tv;
}
}
今あなたの活動では、
CustomAdapter adp = new CustomAdapter(this, R.layout.custom_item, filelist);
mainlist.setAdapter(adp);
mainlist.setTextFilterEnabled(true);
mainlist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
String unique_value=CustomAdapter.hashkeys.get(position);//get value on click of item
}
});