finish activity from custom BaseAdapter
In my android application I have custom listview with an image and textview. In extended BaseAdapter under getView method click events of textview and image are associated with onClick method using setOnClickListener as shown in code below
public View getView(int position, View convertView, ViewGroup viewGroup) {
String entry = listWords.get(position);
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.history_row, null);
}
TextView txtWordView = (TextView) convertView.findViewById(R.id.txtWordView);
txtWordView.setText(entry);
txtWordView.setOnClickListener(this);
txtWordView.setTag(entry);
ImageView imgRemove = (ImageView) convertView.findViewById(R.id.del_x);
imgRemove.setOnClickListener(this);
imgRemove.setTag(entry);
return convertView;
}
and
public void onClick(View view) {
try {
if(view instanceof TextView){
//Here i would like this to finish this activity with result being sent to main
//activity - something like this
//Intent result = getIntent();
//result.putExtra("word", _strList.get(location));
//setResult(RESULT_OK, result);
//finish();
} else {
String entry = (String) view.getTag();
listWords.remove(entry);
History objHistory = new History(this.context);
objHistory.clearHistory(entry);
}
notifyDataSetChanged();
} catch (Exception e) {
}
}
When clicking on image it acutally deletes that entry from List which works fine, but on clicking textview i would like to return the text of clicked textview to main activity but I am unable to achieve this, although I can do this from setOnItemClickListener of this custo开发者_开发百科m listview acitivity.
You can pass your activity object into the constructor of baseActivity, then you can do whatever you want with it.
精彩评论