0

我没有将结果从活动中返回到片段

这是我的夏洛克片段代码

public class AlphabeticalListFragment extends SherlockFragment {
.
.
.
public void setAdapter(){
    adapter = new ListviewAlphabetAdapter(context, alphabet_data);
    lv_list.setAdapter(adapter);
    }
.
.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
            Toast.makeText(context, "RESULT : " + requestCode + "-" + resultCode,
                        Toast.LENGTH_SHORT).show();
            }
        }

我的适配器代码是

public class ListviewAlphabetAdapter extends BaseAdapter{
.
.

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = mInflater.inflate(R.layout.template_list_letter_view,
                null);
          holder.ll_store_data.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i_dialog = new Intent(context,
                        DialogStoreAllActivity.class);
                i_dialog.putExtra("id", alphabet_data.get(position).getI());
                ((Activity) context).startActivityForResult(i_dialog, 500);
            }
        });
        return convertView;
    }
}

在活动中

public class DialogStoreAllActivity extends Activity{
.
.
// In onClick function of a button
setResult(RESULT_OK, (i_groups).setAction("ok"));
.
}

我没有在片段中得到结果

4

1 回答 1

1

像这样在活动类中编写一个函数

public void startCommentActivity(Intent i){
startActivityForResult(i, 100);

}

在适配器类 mActivity.startCommentActivity(intent) 中调用它;

于 2014-05-07T03:39:08.437 回答