Frage

Hie Friends.

I have:

  • List View that have Images thumbs stored via CustomAdapter.

  • One Preview Button which is not a part of listview.

My Requirement is:

When User select Image-Thumb of listView the new Activity Should open with the URL of selected Thumb.

I parse Images and Thumbs from JSON.

Can anyone please help me how can I do this?

My Code is:

public class ECard_main extends Activity 
{
    String catagories;
    String anim_id,album_id,anim_name,anim_thumb,anim_url;
    int global_position; 
    String anim_url_pass;

    ImageView btnpreview;
    TextView title;
    public static boolean isQuit = false;

    HorizontalListView hlv;
    ArrayList<HashMap<String, String>> albumList;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ecard_main);

        btnpreview=(ImageView)findViewById(R.id.iv_preview);
        title.setText(catagories);

        hlv = (HorizontalListView)findViewById(R.id.listData);
        albumList = new ArrayList<HashMap<String, String>>();

        hlv.setOnItemClickListener(new OnItemClickListener()
        {
                @Override
                public void onItemClick(AdapterView<?> arg0, View view,
                         int position, long arg3)
                {
                    // TODO Auto-generated method stub
                     Toast.makeText(getApplicationContext(), "POSITION: "+position,Toast.LENGTH_SHORT).show();
                     btnpreview.setTag(position);
                     global_position=position;
                }
            }
        );

        AsycLove().execute();
    }
    public void onClick_preview(View v)
    {
        Intent i=new Intent(ECard_main.this,Preview.class);

        Toast.makeText(getApplicationContext(),"Position in Preview::"+global_position,Toast.LENGTH_SHORT).show();
        i.putExtra("Catagories", catagories);
        i.putExtra("Web_Url", anim_url);

        startActivity(i);
    }
    class AsycLove extends AsyncTask<String, String, String>     
    {
        ProgressDialog progressDialog;      

        @Override
        protected void onPreExecute() 
        {
            super.onPreExecute();            
            progressDialog = new ProgressDialog(ECard_main.this);
            progressDialog.setTitle("Loading");
            progressDialog.setMessage("Please wait");

        }

        @Override
        protected String doInBackground(String... aurl)        
        {           
            try 
            {
                HttpPost postMethod = new HttpPost("http://demo1.idevtechnolabs.com/smartecard/love.php");              
                BufferedReader bufferedReader = null;

                HttpClient client = new DefaultHttpClient();
                HttpResponse response = null;

                response = client.execute(postMethod);
                final int statusCode = response.getStatusLine().getStatusCode();

                bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                StringBuffer stringBuffer = new StringBuffer("");
                String line = "";
                String LineSeparator = System.getProperty("line.separator");
                while ((line = bufferedReader.readLine()) != null) 
                {
                    stringBuffer.append(line + LineSeparator); 
                }
                bufferedReader.close(); 

                //-------------CONVERT DATA TO JSON---------------------------------

                try 
                {
                    String myjsonstring = stringBuffer.toString();
                    JSONArray jsonArray = new JSONArray(myjsonstring);
                    JSONObject jsonObj = null;
                    albumList.clear();
                    jsonObj = jsonArray.getJSONObject(0);   

                    for(int i=0; i<jsonArray.length();i++)
                    {
                            jsonObj = jsonArray.getJSONObject(i);                           

                            anim_id = jsonObj.getString("animation_id");      
                            album_id = jsonObj.getString("album_id");
                            anim_name = jsonObj.getString("animation_name");      
                            anim_thumb= jsonObj.getString("animation_thumb");

                            anim_url = jsonObj.getString("animation_url");

                            anim_url=anim_url.replaceAll("\"","");


                            HashMap<String, String> tmp_album = new HashMap<String, String>();
                            tmp_album.put("anim_id", anim_id);
                            tmp_album.put("anim_thumb", anim_thumb);
                            tmp_album.put("anim_url",anim_url);

                            albumList.add(tmp_album);
                            Log.v("Animation URL Position","Animation::"+global_position+"::"+anim_url);

                    }

                } 
                catch (Exception e) 
                {
                    Log.v("Home ::","Call JSON Exception in get Album in List--->"+e.toString());
                    e.printStackTrace();
                }
            } 
            catch (IOException e) 
            {
                Log.v("Exception: Get get Album in List","Name-"+e.toString());
                e.printStackTrace();
            }

            return "0";
        }

        @Override
        protected void onPostExecute(String code) 
        {   
            Toast.makeText(getApplicationContext(), "Image URL Call Successfully", Toast.LENGTH_LONG).show();
            Log.v("Album","Album List::"+albumList);

            ECard_main_Custom_Adapter adapter =new ECard_main_Custom_Adapter(getApplicationContext(),albumList,ECard_main.this);
            hlv.setAdapter(adapter);    

            progressDialog.dismiss();
            progressDialog = null;

        }
    }

}

Please tell me where I am doing mistake and how can I get the solution?

Thank you

War es hilfreich?

Lösung

Finally I got the Solution:

public void onClick_preview(View v)
    { 
        for(int p=0;p<=albumList.size();p++)
        {

            String animation_id=albumList.get(p).get("anim_id");

            if(Integer.parseInt(animation_id)==global_position)
            {
                animation_url=albumList.get(p).get("anim_url");
                break;
            }
        }
        Intent i=new Intent(ECard_main.this,Preview.class);
        i.putExtra("Catagories", catagories);
        i.putExtra("Web_Url", animation_url);
        startActivity(i);
    }

Andere Tipps

    hlv = (HorizontalListView)findViewById(R.id.listData);
    btnpreview=(ImageView)hlv.findViewById(R.id.iv_preview);
    title.setText(catagories);

if your button is in a lilst item you want to initialize your button like this

 hlv.setOnItemClickListener(new OnItemClickListener()
    {
            @Override
            public void onItemClick(AdapterView<?> arg0, View view,
                     int position, long arg3)
            {
                // TODO Auto-generated method stub
                 Toast.makeText(getApplicationContext(), "POSITION: "YourArrayList.get(position).get("your_image_url_tag");+,Toast.LENGTH_SHORT).show();
                 btnpreview.setTag(position);
                 global_position=position;
            }
        }
    );
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top