从listview的自定义适配器中接收意图服务的结果

Sor*_*ora 9 android listview android-intent

我想要做的是以下

  1. 我的自定义适配器布局中有一个按钮,它与服务器上的php脚本交互,以便在服务器上下载文件
  2. 下载过程通过IntentService在后台调用来处理
  3. 当服务完成后,我想更新我在活动中启动的列表视图
  4. 我被困在Receiver班上

我的代码到目前为止如下:

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        if(IsRepository){
            view = vi.inflate(R.layout.filerepositorylayout, null);
        }
     }
      BindLayoutElemnts(view, position);
    return view;
  }
Run Code Online (Sandbox Code Playgroud)

这是调用Intent服务的地方:

 private void BindLayoutElemnts(View view, int position) {
      myFiles = (files) getItem(position);
       img_Download.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(getContext(),DownloadService.class);
            intent.putExtra("FileID",""+myFiles.getID());
            intent.putExtra("FileName",myFiles.getName());
            context.startService(intent);
        }
    });
 }
Run Code Online (Sandbox Code Playgroud)

呼叫活动

Receiver是被称为的地方

    public class user_repositry extends AppCompatActivity implements  DownloadReceiver.Receiver {
 protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       myDownloadReceiver = new DownloadReceiver(new Handler());
       myDownloadReceiver.setReceiver(this);
 }

  @Override
public void onReceiveResult(int resultCode, Bundle resultData) {
    Toast.makeText(user_repositry.this, "Downloaded", Toast.LENGTH_SHORT).show();

}
Run Code Online (Sandbox Code Playgroud)

Intent service代码:

 ResultReceiver rec;
 @Override
protected void onHandleIntent(Intent intent) {
      rec = intent.getParcelableExtra("DownloadReceiver");
}

 private void UpdateDBRecord() {
    HashMap<String, String>  PostData=new HashMap<String, String>();
    PostData.put("call","UpdateFile");
    PostData.put("ID", ""+file_ID);
    BackgroundWorker registerWorker= new BackgroundWorker(this,this,PostData);
    registerWorker.setShowLoadingMessage(false);
    registerWorker.execute(Helper.getPhpHelperUrl());
}
Run Code Online (Sandbox Code Playgroud)

这个函数是Post executeregisterWorker上面调用的函数

 @Override
public void processFinish(String results) {
    Log.d("Download","Download DB updated");
    Bundle bundle = new Bundle();
    //bundle.putString("resultValue", "My Result Value. Passed in: " );
    // Here we call send passing a resultCode and the bundle of extras
    rec.send(Activity.RESULT_OK, bundle);
}
Run Code Online (Sandbox Code Playgroud)

我现在卡住了这个错误:

Failed resolution of: Lcom/bassem/donateme/classes/DownloadReceiver;
Run Code Online (Sandbox Code Playgroud)

我知道接收器没有被启动但我似乎无法在我的逻辑中找到丢失的代码

感谢您的帮助

Tat*_*ize 0

缺少的代码不在您的逻辑中,而是在 DownloadReciever 的逻辑中。更广泛地查找错误并找出无法加载的原因。或者从中发布一些代码以便可以回答。是不是例如寻找一个不存在的uri从而崩溃?它期待什么、失败什么以及为什么失败。您没有发布任何崩溃的代码。您发布了调用崩溃的代码。