手指触摸从左到右的幻灯片图像(图片来自URL)

时间:2015-05-15 19:35:19

标签: android image url touch slide

我想从左向右滑动或移动图像。 我尝试了一下但没有这样做我使用下面的代码 我从parse.com从URL检索图像 我的第一个活动,我将图像的int位置和URL传递给我的第二个活动

  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview_main);
    Intent i = getIntent();
    // Get the name
    name = i.getStringExtra("name").replace(" ", "_");
    position = i.getExtras().getInt("id");
    Log.d("Tag Name", position+name);
    // Execute RemoteDataTask AsyncTask
    new RemoteDataTask().execute();
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(MyFirstActivity.this);
        mProgressDialog.setTitle("Listing...");
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }
    @Override
    protected Void doInBackground(Void... params) {
    // Locate the class in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                name);
        query.orderByAscending("sort");
        try {
            ob = query.find();
        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        listview = (ListView) findViewById(R.id.listview);
        adapter = new ArrayAdapter<String>(MyFirstActivity.this,
                R.layout.listview_item,R.id.text);
     // Retrieve object Parse.com database
        for (ParseObject country : ob) {
            adapter.add((String) country.get("name"));
            country.get("Murl");
        }
        listview.setAdapter(adapter);
        mProgressDialog.dismiss();
        listview.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                Intent i = new Intent(MyFirstActivity.this,
                        SecondActivity.class);
            // Pass data "name" followed by the position
                i.putExtra("Murl", ob.get(position).getString("Murl")
                        .toString());
                i.putExtra("id", position);
            // Open SecondActivity.java Activity
                startActivity(i);
            }
        });
    }
}

在我的第二个活动中,我成功地在imageview中加载图像,但是不知道如何从左到右手指触摸加载图像? 在这里,我不知道如何使用int position和URL来加载上一个Activity的下一个图像。 这是我的第二个活动代码请帮助

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.singleitemview1);
    Intent i = getIntent();
    // Get the name
    name = i.getStringExtra("Nurl");
    position = i.getExtras().getInt("id");
    Log.d("Tag Name", position + name);
    img = (TouchImageView)findViewById(R.id.imge);
    imgLoader = new ImageLoader(this);
    imgLoader.DisplayImage(name, img);
    new LoadImage().execute(name);
}
private class LoadImage extends AsyncTask<String, String, Bitmap> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(SingleItemView1.this);
        pDialog.setMessage("Loading Image ....");
        pDialog.show();
    }
    protected Bitmap doInBackground(String... args) {
        try {
            bitmap = BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }
    protected void onPostExecute(Bitmap image) {

        if(image != null){
            img.setImageBitmap(image);
            pDialog.dismiss();
        }else{
            pDialog.dismiss();
            Toast.makeText(SecondActivity.this, "Image Does Not exist or Network Error", Toast.LENGTH_SHORT).show();
        }
    }
}

0 个答案:

没有答案