单击列表视图中的项目后,它必须转到各自的链接

时间:2013-03-09 06:19:10

标签: java android

这是否可以将链接作为数组提供,我们可以根据列表项的相应克隆获取链接,在我的代码中我将硬编码我的链接看起来不太好,我需要什么我想要给所有在列表视图中单击项目后,它必须打开相应的链接。

public class SouthIndianvegrecipes  extends Activity  {

    //private Button Manual;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);

        ArrayList<Recipedetails1> image_details = GetSearchResults();

        final ListView lv1 = (ListView) findViewById(R.id.listV1_main);
        lv1.setAdapter(new ItemListBaseAdapter1(this, image_details));

        lv1.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
                Object o = lv1.getItemAtPosition(position);
                Recipedetails1 obj_itemDetails = (Recipedetails1)o;
                Toast.makeText(SouthIndianvegrecipes.this, "You have chosen : " + " " + obj_itemDetails.getName1(), Toast.LENGTH_LONG).show();


            } 
        });
    }

    private ArrayList<Recipedetails1> GetSearchResults(){
        ArrayList<Recipedetails1> results = new ArrayList<Recipedetails1>();

        Recipedetails1 item_details = new Recipedetails1();
        item_details.setName1("Vegterian");
        item_details.setItemDescription1("Recipes made by raw materials");
        item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
        item_details.setImageNumber1(1);
        results.add(item_details);

        item_details = new Recipedetails1();
        item_details.setName1("Non-Vegterian");
        item_details.setItemDescription1("Flesh of sweet animals");
        item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
        item_details.setImageNumber1(2);
        results.add(item_details);

        item_details = new Recipedetails1();
        item_details.setName1("Pickels");
        item_details.setItemDescription1("Touchable dish  by Homemade");
        item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
        item_details.setImageNumber1(3);
        results.add(item_details);

        item_details = new Recipedetails1();
        item_details.setName1("Soups");
        item_details.setItemDescription1("Startup for our food");
        item_details.setUrlWiki("https://www.youtube.com/watch?v=C_r0mFvMSfU");
        item_details.setImageNumber1(4);
        results.add(item_details);




        return results;
    }
}

我想点击列表中的项目,它必须为视频分别显示相应的链接,但现在我将其置于持有者中,它会直接显示链接,看起来不太好。

1 个答案:

答案 0 :(得分:2)

只需为视频启动Intent即可。这应该有效:

@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
  Object o = lv1.getItemAtPosition(position);
  Recipedetails1 obj_itemDetails = (Recipedetails1)o;
  final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(o.getUrlWiki()));
  startActivity(i);
}