2010-11-22 9 views
1

私のアンドロイドアプリケーションでは、イメージとテキストビューを持つカスタムリストビューを持っています。画像をクリックすると、コードに示すようにのTextViewと画像のGetViewメソッドクリックイベント下拡張BaseAdapterにカスタムBaseAdapterからアクティビティを完了

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; 
} 

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) { 
    } 
} 

の下setOnClickListenerを使用してのonClickメソッドに関連付けられていることがacutallyリストからそのエントリを削除しますこれはうまく動作しますが、textviewをクリックすると、クリックされたtextviewのテキストをメインアクティビティに戻したいのですが、これを達成することはできませんが、このカスタムlistviewアクティビティのsetOnItemClickListenerから実行できます。

答えて

2

あなたのアクティビティオブジェクトをbaseActivityのコンストラクタに渡すことができます。そして、あなたはそれを使って何でもできます。

+0

nice!それは動作する、私はそれが簡単になることを知っていない – Waqas

関連する問題